<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Hibernate ORM User Guide - Hibernate ORM 5.4.18.Final User Guide | Docs4dev</title>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="description" content="Domain model persistence for relational databases.">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="HandheldFriendly" content="true">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta property="og:type" content="website">
<meta property="og:title" content="Hibernate ORM User Guide - Hibernate ORM 5.4.18.Final User Guide">
<meta property="og:url" content="https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/">
<meta property="og:site_name" content="Docs4dev">
<meta property="og:locale" content="zh_CN">
<meta name="twitter:card" content="Domain model persistence for relational databases.">
<meta name="generator" content="Docs4dev template engine">
<link rel="stylesheet" href="static/css/app.min.css">
<link rel="shortcut icon" href="https://www.docs4dev.com/static/images/favicon.ico" type="image/x-icon">
<script async="" src="static/js/js.js"></script>
<script async="" src="static/js/adsbygoogle.js" crossorigin="anonymous"></script>
<script>
    window.dataLayer = window.dataLayer || [];

    function gtag() {
      dataLayer.push(arguments);
    }

    gtag('js', new Date());
    gtag('config', 'UA-129571937-1');
  </script>
<link rel="amphtml" href="https://www.docs4dev.com/amp/docs/en/hibernate-orm/5.4/reference/index.html">

<script type="application/ld+json">{"name":null,"headline":"Hibernate ORM User Guide-Hibernate ORM 5.4.18.Final User Guide","inLanguage":"en-US","version":"5.4","image":"/static/icon/icon-hibernate.jpg","datePublished":"2021-05-20T12:51:01Z","dateCreated":"2021-05-20T12:51:01Z","dateModified":"2021-07-03T12:24:36Z","@context":"https://schema.org/","@type":"APIReference","abstract":"Domain model persistence for relational databases."}</script>
</head>
<body>
<div class="book with-summary">
<div class="book-summary">
<div class="logo">
<a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference');" style="color: inherit;">
<img src="static/picture/icon-hibernate.jpg" style="width: 48px; height: 48px;" alt="Logo">
</a>
<b style="color: inherit; margin-left: 8px;">Hibernate ORM User Guide</b>
</div>
<div class="item">
<div>
<label for="version">版本</label>
<select id="version" onchange="onVersionChange(this)">
<option value="5.4" selected="selected">5.4</option>
</select>
</div>
<div style="margin-top: 8px;">
<label for="language">语言</label>
<select id="language" onchange="onLangChange(this)" value="en">
<option value="en" selected="selected">English</option>
<option value="zh">中文</option>
</select>
</div>

</div>
<div class="item menus">
<a title="Table of Contents" style="margin-right: 8px;" href="#">
<i class="fa fa-chevron-left"></i>
<span style="margin-left: 2px;">返回目录</span>
</a>
</div>
<nav role="navigation" id="navigation">
<ul class="summary">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#preface');" title="Preface"> Preface </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_get_involved');" title="Get Involved"> Get Involved </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_system_requirements');" title="System Requirements"> System Requirements </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_getting_started_guide');" title="Getting Started Guide"> Getting Started Guide </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#architecture');" title="1. Architecture"> 1. Architecture </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#architecture-overview');" title="1.1. Overview"> 1.1. Overview </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#domain-model');" title="2. Domain Model"> 2. Domain Model </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#mapping-types');" title="2.1. Mapping types"> 2.1. Mapping types </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#naming');" title="2.2. Naming strategies"> 2.2. Naming strategies </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#basic');" title="2.3. Basic types"> 2.3. Basic types </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#embeddables');" title="2.4. Embeddable types"> 2.4. Embeddable types </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#entity');" title="2.5. Entity types"> 2.5. Entity types </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#identifiers');" title="2.6. Identifiers"> 2.6. Identifiers </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#associations');" title="2.7. Associations"> 2.7. Associations </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#collections');" title="2.8. Collections"> 2.8. Collections </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#naturalid');" title="2.9. Natural Ids"> 2.9. Natural Ids </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#dynamic-model');" title="2.10. Dynamic Model"> 2.10. Dynamic Model </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#entity-inheritance');" title="2.11. Inheritance"> 2.11. Inheritance </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#entity-immutability');" title="2.12. Immutability"> 2.12. Immutability </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#bootstrap');" title="3. Bootstrap"> 3. Bootstrap </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#bootstrap-native');" title="3.1. Native Bootstrapping"> 3.1. Native Bootstrapping </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#bootstrap-jpa');" title="3.2. JPA Bootstrapping"> 3.2. JPA Bootstrapping </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#schema-generation');" title="4. Schema generation"> 4. Schema generation </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#schema-generation-script-files');" title="4.1. Importing script files"> 4.1. Importing script files </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#schema-generation-database-objects');" title="4.2. Database objects"> 4.2. Database objects </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#schema-generation-database-checks');" title="4.3. Database-level checks"> 4.3. Database-level checks </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#schema-generation-column-default-value');" title="4.4. Default value for a database column"> 4.4. Default value for a database column </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#schema-generation-columns-unique-constraint');" title="4.5. Columns unique constraint"> 4.5. Columns unique constraint </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#schema-generation-columns-index');" title="4.6. Columns index"> 4.6. Columns index </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#pc');" title="5. Persistence Context"> 5. Persistence Context </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#pc-unwrap');" title="5.1. Accessing Hibernate APIs from JPA"> 5.1. Accessing Hibernate APIs from JPA </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#BytecodeEnhancement');" title="5.2. Bytecode Enhancement"> 5.2. Bytecode Enhancement </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#pc-persist');" title="5.3. Making entities persistent"> 5.3. Making entities persistent </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#pc-remove');" title="5.4. Deleting (removing) entities"> 5.4. Deleting (removing) entities </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#pc-get-reference');" title="5.5. Obtain an entity reference without initializing its data"> 5.5. Obtain an entity reference without initializing its data </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#pc-find');" title="5.6. Obtain an entity with its data initialized"> 5.6. Obtain an entity with its data initialized </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#pc-by-multiple-ids');" title="5.7. Obtain multiple entities by their identifiers"> 5.7. Obtain multiple entities by their identifiers </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#pc-find-natural-id');" title="5.8. Obtain an entity by natural-id"> 5.8. Obtain an entity by natural-id </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#pc-filtering');" title="5.9. Filtering entities and associations"> 5.9. Filtering entities and associations </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#pc-managed-state');" title="5.10. Modifying managed/persistent state"> 5.10. Modifying managed/persistent state </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#pc-refresh');" title="5.11. Refresh entity state"> 5.11. Refresh entity state </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#pc-detach');" title="5.12. Working with detached data"> 5.12. Working with detached data </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#pc-contains');" title="5.13. Checking persistent state"> 5.13. Checking persistent state </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_evicting_entities');" title="5.14. Evicting entities"> 5.14. Evicting entities </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#pc-cascade');" title="5.15. Cascading entity state transitions"> 5.15. Cascading entity state transitions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#pc-exception-handling');" title="5.16. Exception handling"> 5.16. Exception handling </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#flushing');" title="6. Flushing"> 6. Flushing </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#flushing-auto');" title="6.1. AUTO flush"> 6.1. AUTO flush </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#flushing-commit');" title="6.2. COMMIT flush"> 6.2. COMMIT flush </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#flushing-always');" title="6.3. ALWAYS flush"> 6.3. ALWAYS flush </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#flushing-manual');" title="6.4. MANUAL flush"> 6.4. MANUAL flush </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#flushing-order');" title="6.5. Flush operation order"> 6.5. Flush operation order </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#database');" title="7. Database access"> 7. Database access </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#database-connectionprovider');" title="7.1. ConnectionProvider"> 7.1. ConnectionProvider </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#database-connectionprovider-datasource');" title="7.2. Using DataSources"> 7.2. Using DataSources </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#database-connectionprovider-driver');" title="7.3. Driver Configuration"> 7.3. Driver Configuration </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#database-connectionprovider-c3p0');" title="7.4. Using c3p0"> 7.4. Using c3p0 </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#database-connectionprovider-proxool');" title="7.5. Using Proxool"> 7.5. Using Proxool </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#database-connectionprovider-hikari');" title="7.6. Using HikariCP"> 7.6. Using HikariCP </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#database-connectionprovider-vibur');" title="7.7. Using Vibur DBCP"> 7.7. Using Vibur DBCP </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#database-connectionprovider-agroal');" title="7.8. Using Agroal"> 7.8. Using Agroal </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#database-connectionprovider-drivermanager');" title="7.9. Using Hibernate’s built-in (and unsupported) pooling"> 7.9. Using Hibernate’s built-in (and unsupported) pooling </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#database-connectionprovider-provided');" title="7.10. User-provided Connections"> 7.10. User-provided Connections </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#database-connectionprovider-isolation');" title="7.11. ConnectionProvider support for transaction isolation setting"> 7.11. ConnectionProvider support for transaction isolation setting </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#database-connection-handling');" title="7.12. Connection handling"> 7.12. Connection handling </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#database-dialect');" title="7.13. Database Dialect"> 7.13. Database Dialect </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#transactions');" title="8. Transactions and concurrency control"> 8. Transactions and concurrency control </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#transactions-physical');" title="8.1. Physical Transactions"> 8.1. Physical Transactions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#transactions-physical-jtaplatform');" title="8.2. JTA configuration"> 8.2. JTA configuration </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#transactions-api');" title="8.3. Hibernate Transaction API"> 8.3. Hibernate Transaction API </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#architecture-current-session');" title="8.4. Contextual sessions"> 8.4. Contextual sessions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_transactional_patterns_and_anti_patterns');" title="8.5. Transactional patterns (and anti-patterns)"> 8.5. Transactional patterns (and anti-patterns) </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#jndi');" title="9. JNDI"> 9. JNDI </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#locking');" title="10. Locking"> 10. Locking </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#locking-optimistic');" title="10.1. Optimistic"> 10.1. Optimistic </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#locking-pessimistic');" title="10.2. Pessimistic"> 10.2. Pessimistic </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#locking-LockMode');" title="10.3. LockMode and LockModeType"> 10.3. LockMode and LockModeType </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#locking-jpa-query-hints');" title="10.4. JPA locking query hints"> 10.4. JPA locking query hints </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#locking-buildLockRequest');" title="10.5. The buildLockRequest API"> 10.5. The buildLockRequest API </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#locking-follow-on');" title="10.6. Follow-on-locking"> 10.6. Follow-on-locking </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#fetching');" title="11. Fetching"> 11. Fetching </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#fetching-basics');" title="11.1. The basics"> 11.1. The basics </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#fetching-direct-vs-query');" title="11.2. Direct fetching vs. entity queries"> 11.2. Direct fetching vs. entity queries </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#fetching-strategies');" title="11.3. Applying fetch strategies"> 11.3. Applying fetch strategies </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#fetching-strategies-no-fetching');" title="11.4. No fetching"> 11.4. No fetching </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#fetching-strategies-dynamic-fetching');" title="11.5. Dynamic fetching via queries"> 11.5. Dynamic fetching via queries </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#fetching-strategies-dynamic-fetching-entity-graph');" title="11.6. Dynamic fetching via JPA entity graph"> 11.6. Dynamic fetching via JPA entity graph </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#fetching-strategies-dynamic-fetching-profile');" title="11.7. Dynamic fetching via Hibernate profiles"> 11.7. Dynamic fetching via Hibernate profiles </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#fetching-batch');" title="11.8. Batch fetching"> 11.8. Batch fetching </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#fetching-fetch-annotation');" title="11.9. The @Fetch annotation mapping"> 11.9. The @Fetch annotation mapping </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#fetching-fetchmode-select');" title="11.10. FetchMode.SELECT"> 11.10. FetchMode.SELECT </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#fetching-fetchmode-subselect');" title="11.11. FetchMode.SUBSELECT"> 11.11. FetchMode.SUBSELECT </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#fetching-fetchmode-join');" title="11.12. FetchMode.JOIN"> 11.12. FetchMode.JOIN </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#fetching-LazyCollection');" title="11.13. @LazyCollection"> 11.13. @LazyCollection </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#batch');" title="12. Batching"> 12. Batching </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#batch-jdbcbatch');" title="12.1. JDBC batching"> 12.1. JDBC batching </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#batch-session-batch');" title="12.2. Session batching"> 12.2. Session batching </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#batch-bulk-hql');" title="12.3. Hibernate Query Language for DML"> 12.3. Hibernate Query Language for DML </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#caching');" title="13. Caching"> 13. Caching </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#caching-config');" title="13.1. Configuring second-level caching"> 13.1. Configuring second-level caching </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#caching-mappings');" title="13.2. Configuring second-level cache mappings"> 13.2. Configuring second-level cache mappings </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#caching-mappings-inheritance');" title="13.3. Entity inheritance and second-level cache mapping"> 13.3. Entity inheritance and second-level cache mapping </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#caching-entity');" title="13.4. Entity cache"> 13.4. Entity cache </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#caching-collection');" title="13.5. Collection cache"> 13.5. Collection cache </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#caching-query');" title="13.6. Query cache"> 13.6. Query cache </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#caching-management');" title="13.7. Managing the cached data"> 13.7. Managing the cached data </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#caching-statistics');" title="13.8. Caching statistics"> 13.8. Caching statistics </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#caching-provider-jcache');" title="13.9. JCache"> 13.9. JCache </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#caching-provider-ehcache');" title="13.10. Ehcache"> 13.10. Ehcache </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#caching-provider-infinispan');" title="13.11. Infinispan"> 13.11. Infinispan </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#events');" title="14. Interceptors and events"> 14. Interceptors and events </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#events-interceptors');" title="14.1. Interceptors"> 14.1. Interceptors </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#events-events');" title="14.2. Native Event system"> 14.2. Native Event system </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#events-mixing-events-and-interceptors');" title="14.3. Mixing Events and Interceptors"> 14.3. Mixing Events and Interceptors </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#events-declarative-security');" title="14.4. Hibernate declarative security"> 14.4. Hibernate declarative security </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#events-jpa-callbacks');" title="14.5. JPA Callbacks"> 14.5. JPA Callbacks </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#events-default-listener');" title="14.6. Default entity listeners"> 14.6. Default entity listeners </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql');" title="15. HQL and JPQL"> 15. HQL and JPQL </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-examples-domain-model');" title="15.1. Example domain model"> 15.1. Example domain model </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#query-api');" title="15.2. Query API"> 15.2. Query API </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-case-sensitivity');" title="15.3. Case Sensitivity"> 15.3. Case Sensitivity </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-statement-types');" title="15.4. Statement types"> 15.4. Statement types </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-select');" title="15.5. Select statements"> 15.5. Select statements </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-update');" title="15.6. Update statements"> 15.6. Update statements </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-delete');" title="15.7. Delete statements"> 15.7. Delete statements </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-insert');" title="15.8. Insert statements"> 15.8. Insert statements </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-from-clause');" title="15.9. The FROM clause"> 15.9. The FROM clause </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-identification-variables');" title="15.10. Identification variables"> 15.10. Identification variables </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-root-reference');" title="15.11. Root entity references"> 15.11. Root entity references </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-explicit-join');" title="15.12. Explicit joins"> 15.12. Explicit joins </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-implicit-join');" title="15.13. Implicit joins (path expressions)"> 15.13. Implicit joins (path expressions) </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-distinct');" title="15.14. Distinct"> 15.14. Distinct </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-collection-valued-associations');" title="15.15. Collection member references"> 15.15. Collection member references </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-collection-qualification');" title="15.16. Special case - qualified path expressions"> 15.16. Special case - qualified path expressions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-polymorphism');" title="15.17. Polymorphism"> 15.17. Polymorphism </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-expressions');" title="15.18. Expressions"> 15.18. Expressions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-identification-variable');" title="15.19. Identification variable"> 15.19. Identification variable </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-path-expressions');" title="15.20. Path expressions"> 15.20. Path expressions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-literals');" title="15.21. Literals"> 15.21. Literals </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-numeric-arithmetic');" title="15.22. Arithmetic"> 15.22. Arithmetic </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-concatenation');" title="15.23. Concatenation (operation)"> 15.23. Concatenation (operation) </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-aggregate-functions');" title="15.24. Aggregate functions"> 15.24. Aggregate functions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-exp-functions');" title="15.25. Scalar functions"> 15.25. Scalar functions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#jpql-standardized-functions');" title="15.26. JPQL standardized functions"> 15.26. JPQL standardized functions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-functions');" title="15.27. HQL functions"> 15.27. HQL functions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-user-defined-functions');" title="15.28. User-defined functions"> 15.28. User-defined functions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-collection-expressions');" title="15.29. Collection-related expressions"> 15.29. Collection-related expressions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-entity-type-exp');" title="15.30. Entity type"> 15.30. Entity type </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-case-expressions');" title="15.31. CASE expressions"> 15.31. CASE expressions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-simple-case-expressions');" title="15.32. Simple CASE expressions"> 15.32. Simple CASE expressions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-searched-case-expressions');" title="15.33. Searched CASE expressions"> 15.33. Searched CASE expressions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-case-arithmetic-expressions');" title="15.34. CASE expressions with arithmetic operations"> 15.34. CASE expressions with arithmetic operations </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-nullif');" title="15.35. NULLIF expressions"> 15.35. NULLIF expressions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_coalesce_expressions');" title="15.36. COALESCE expressions"> 15.36. COALESCE expressions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-select-clause');" title="15.37. The SELECT clause"> 15.37. The SELECT clause </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-conditional-expressions');" title="15.38. Predicates"> 15.38. Predicates </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-relational-comparisons');" title="15.39. Relational comparisons"> 15.39. Relational comparisons </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-null-predicate');" title="15.40. Nullness predicate"> 15.40. Nullness predicate </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-like-predicate');" title="15.41. Like predicate"> 15.41. Like predicate </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-between-predicate');" title="15.42. Between predicate"> 15.42. Between predicate </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-in-predicate');" title="15.43. In predicate"> 15.43. In predicate </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-exists-predicate');" title="15.44. Exists predicate"> 15.44. Exists predicate </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-empty-collection-predicate');" title="15.45. Empty collection predicate"> 15.45. Empty collection predicate </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-member-of-collection-predicate');" title="15.46. Member-of collection predicate"> 15.46. Member-of collection predicate </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-not-predicate');" title="15.47. NOT predicate operator"> 15.47. NOT predicate operator </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-and-predicate');" title="15.48. AND predicate operator"> 15.48. AND predicate operator </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-or-predicate');" title="15.49. OR predicate operator"> 15.49. OR predicate operator </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-where-clause');" title="15.50. The WHERE clause"> 15.50. The WHERE clause </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-group-by');" title="15.51. Group by"> 15.51. Group by </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-order-by');" title="15.52. Order by"> 15.52. Order by </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-read-only-entities');" title="15.53. Read-only entities"> 15.53. Read-only entities </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#hql-query-plan-cache');" title="15.54. Entity query plan cache"> 15.54. Entity query plan cache </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria');" title="16. Criteria"> 16. Criteria </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-typedquery');" title="16.1. Typed criteria queries"> 16.1. Typed criteria queries </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-typedquery-entity');" title="16.2. Selecting an entity"> 16.2. Selecting an entity </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-typedquery-expression');" title="16.3. Selecting an expression"> 16.3. Selecting an expression </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-typedquery-multiselect');" title="16.4. Selecting multiple values"> 16.4. Selecting multiple values </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-typedquery-wrapper');" title="16.5. Selecting a wrapper"> 16.5. Selecting a wrapper </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-tuple');" title="16.6. Tuple criteria queries"> 16.6. Tuple criteria queries </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-from');" title="16.7. FROM clause"> 16.7. FROM clause </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-from-root');" title="16.8. Roots"> 16.8. Roots </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-from-join');" title="16.9. Joins"> 16.9. Joins </a> </li> 
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-from-fetch');" title="16.10. Fetches"> 16.10. Fetches </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-path');" title="16.11. Path expressions"> 16.11. Path expressions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-param');" title="16.12. Using parameters"> 16.12. Using parameters </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-group-by');" title="16.13. Using group by"> 16.13. Using group by </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#sql');" title="17. Native SQL Queries"> 17. Native SQL Queries </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#sql-jpa-query');" title="17.1. Creating a native query using JPA"> 17.1. Creating a native query using JPA </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#sql-scalar-query');" title="17.2. Scalar queries"> 17.2. Scalar queries </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#sql-entity-query');" title="17.3. Entity queries"> 17.3. Entity queries </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#sql-entity-associations-query');" title="17.4. Handling associations and collections"> 17.4. Handling associations and collections </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#sql-multi-entity-query');" title="17.5. Returning multiple entities"> 17.5. Returning multiple entities </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#sql-alias-references');" title="17.6. Alias and property references"> 17.6. Alias and property references </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#sql-dto-query');" title="17.7. Returning DTOs (Data Transfer Objects)"> 17.7. Returning DTOs (Data Transfer Objects) </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#sql-inheritance-query');" title="17.8. Handling inheritance"> 17.8. Handling inheritance </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#sql-query-parameters');" title="17.9. Parameters"> 17.9. Parameters </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#sql-named-queries');" title="17.10. Named SQL queries"> 17.10. Named SQL queries </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#sql-global-catalog-schema');" title="17.11. Resolving global catalog and schema in native SQL queries"> 17.11. Resolving global catalog and schema in native SQL queries </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#sql-sp');" title="17.12. Using stored procedures for querying"> 17.12. Using stored procedures for querying </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#sql-sp-named-query');" title="17.13. Using named queries to call stored procedures"> 17.13. Using named queries to call stored procedures </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#sql-crud');" title="17.14. Custom SQL for CRUD (Create, Read, Update and Delete)"> 17.14. Custom SQL for CRUD (Create, Read, Update and Delete) </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#spatial');" title="18. Spatial"> 18. Spatial </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#spatial-overview');" title="18.1. Overview"> 18.1. Overview </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#spatial-configuration');" title="18.2. Configuration"> 18.2. Configuration </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#spatial-types');" title="18.3. Types"> 18.3. Types </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#multitenacy');" title="19. Multitenancy"> 19. Multitenancy </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#multitenacy-intro');" title="19.1. What is multitenancy?"> 19.1. What is multitenancy? </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#multitenacy-approaches');" title="19.2. Multitenant data approaches"> 19.2. Multitenant data approaches </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#multitenacy-discriminator');" title="19.3. Partitioned (discriminator) data"> 19.3. Partitioned (discriminator) data </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#multitenacy-hibernate');" title="19.4. Multitenancy in Hibernate"> 19.4. Multitenancy in Hibernate </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#osgi');" title="20. OSGi"> 20. OSGi </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_osgi_specification_and_environment');" title="20.1. OSGi Specification and Environment"> 20.1. OSGi Specification and Environment </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_hibernate_osgi');" title="20.2. hibernate-osgi"> 20.2. hibernate-osgi </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_features_xml');" title="20.3. features.xml"> 20.3. features.xml </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_quickstarts_demos');" title="20.4. QuickStarts/Demos"> 20.4. QuickStarts/Demos </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#osgi-managed-jpa');" title="20.5. Container-Managed JPA"> 20.5. Container-Managed JPA </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_enterprise_osgi_jpa_container');" title="20.6. Enterprise OSGi JPA Container"> 20.6. Enterprise OSGi JPA Container </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_persistence_xml');" title="20.7. persistence.xml"> 20.7. persistence.xml </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_datasource');" title="20.8. DataSource"> 20.8. DataSource </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_bundle_package_imports');" title="20.9. Bundle Package Imports"> 20.9. Bundle Package Imports </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_obtaining_an_entitymanger');" title="20.10. Obtaining an EntityManger"> 20.10. Obtaining an EntityManger </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#osgi-unmanaged-jpa');" title="20.11. Unmanaged JPA"> 20.11. Unmanaged JPA </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_persistence_xml_2');" title="20.12. persistence.xml"> 20.12. persistence.xml </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_bundle_package_imports_2');" title="20.13. Bundle Package Imports"> 20.13. Bundle Package Imports </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_obtaining_an_entitymangerfactory');" title="20.14. Obtaining an EntityMangerFactory"> 20.14. Obtaining an EntityMangerFactory </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#osgi-unmanaged-native');" title="20.15. Unmanaged Native"> 20.15. Unmanaged Native </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_bundle_package_imports_3');" title="20.16. Bundle Package Imports"> 20.16. Bundle Package Imports </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_obtaining_a_sessionfactory');" title="20.17. Obtaining a SessionFactory"> 20.17. Obtaining a SessionFactory </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_optional_modules');" title="20.18. Optional Modules"> 20.18. Optional Modules </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_extension_points');" title="20.19. Extension Points"> 20.19. Extension Points </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_caveats');" title="20.20. Caveats"> 20.20. Caveats </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers');" title="21. Envers"> 21. Envers </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-basics');" title="21.1. Basics"> 21.1. Basics </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-configuration');" title="21.2. Configuration Properties"> 21.2. Configuration Properties </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-additional-mappings');" title="21.3. Additional mapping annotations"> 21.3. Additional mapping annotations </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-audit-strategy');" title="21.4. Choosing an audit strategy"> 21.4. Choosing an audit strategy </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-revisionlog');" title="21.5. Revision Log"> 21.5. Revision Log </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-tracking-modified-entities-revchanges');" title="21.6. Tracking entity names modified during revisions"> 21.6. Tracking entity names modified during revisions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-tracking-properties-changes');" title="21.7. Tracking entity changes at the property level"> 21.7. Tracking entity changes at the property level </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-tracking-properties-changes-strategy');" title="21.8. Selecting strategy for tracking property level changes"> 21.8. Selecting strategy for tracking property level changes </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-queries');" title="21.9. Queries"> 21.9. Queries </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#entities-at-revision');" title="21.10. Querying for entities of a class at a given revision"> 21.10. Querying for entities of a class at a given revision </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#entities-filtering');" title="21.11. Querying for entities using filtering criteria"> 21.11. Querying for entities using filtering criteria </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#revisions-of-entity');" title="21.12. Querying for revisions, at which entities of a given class changed"> 21.12. Querying for revisions, at which entities of a given class changed </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-tracking-properties-changes-queries');" title="21.13. Querying for entity revisions that modified a given property"> 21.13. Querying for entity revisions that modified a given property </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-tracking-obtain-properties-changed-queries');" title="21.14. Querying for revisions of entity including property names that were modified"> 21.14. Querying for revisions of entity including property names that were modified </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-tracking-modified-entities-queries');" title="21.15. Querying for entity types modified in a given revision"> 21.15. Querying for entity types modified in a given revision </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-querying-entity-relation-joins');" title="21.16. Querying for entities using entity relation joins"> 21.16. Querying for entities using entity relation joins </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-querying-revision-entities');" title="21.17. Querying for revision information without loading entities"> 21.17. Querying for revision information without loading entities </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-conditional-auditing');" title="21.18. Conditional auditing"> 21.18. Conditional auditing </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-schema');" title="21.19. Understanding the Envers Schema"> 21.19. Understanding the Envers Schema </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-generateschema');" title="21.20. Generating Envers schema with Hibernate hbm2ddl tool"> 21.20. Generating Envers schema with Hibernate hbm2ddl tool </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-mappingexceptions');" title="21.21. Mapping exceptions"> 21.21. Mapping exceptions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_code_onetomany_code_with_code_joincolumn_code');" title="21.22. @OneToMany with @JoinColumn"> 21.22. @OneToMany with @JoinColumn </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-partitioning');" title="21.23. Advanced: Audit table partitioning"> 21.23. Advanced: Audit table partitioning </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-partitioning-benefits');" title="21.24. Benefits of audit table partitioning"> 21.24. Benefits of audit table partitioning </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-partitioning-columns');" title="21.25. Suitable columns for audit table partitioning"> 21.25. Suitable columns for audit table partitioning </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-partitioning-example');" title="21.26. Audit table partitioning example"> 21.26. Audit table partitioning example </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-partitioning-example-column');" title="21.27. Determining a suitable partitioning column"> 21.27. Determining a suitable partitioning column </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-partitioning-example-scheme');" title="21.28. Determining a suitable partitioning scheme"> 21.28. Determining a suitable partitioning scheme </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#envers-links');" title="21.29. Envers links"> 21.29. Envers links </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#portability');" title="22. Database Portability Considerations"> 22. Database Portability Considerations </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#portability-basics');" title="22.1. Portability Basics"> 22.1. Portability Basics </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#portability-dialect');" title="22.2. Dialect"> 22.2. Dialect </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#portability-dialectresolver');" title="22.3. Dialect resolution"> 22.3. Dialect resolution </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#portability-idgen');" title="22.4. Identifier generation"> 22.4. Identifier generation </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#portability-functions');" title="22.5. Database functions"> 22.5. Database functions </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#portability-types');" title="22.6. Type mappings"> 22.6. Type mappings </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#statistics');" title="23. Statistics"> 23. Statistics </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#statistics-methods');" title="23.1. org.hibernate.stat.Statistics methods"> 23.1. org.hibernate.stat.Statistics methods </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#statistics-query-max-size');" title="23.2. Query statistics max size"> 23.2. Query statistics max size </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#statistics-query-plan-cache');" title="23.3. Query plan cache statistics"> 23.3. Query plan cache statistics </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations');" title="24. Configurations"> 24. Configurations </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-strategy');" title="24.1. Strategy configurations"> 24.1. Strategy configurations </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-general');" title="24.2. General configuration"> 24.2. General configuration </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-jpa-compliance');" title="24.3. JPA compliance"> 24.3. JPA compliance </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-database-connection');" title="24.4. Database connection properties"> 24.4. Database connection properties </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-c3p0');" title="24.5. c3p0 properties"> 24.5. c3p0 properties </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-mapping');" title="24.6. Mapping Properties"> 24.6. Mapping Properties </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-bytecode-enhancement');" title="24.7. Bytecode Enhancement Properties"> 24.7. Bytecode Enhancement Properties </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-query');" title="24.8. Query settings"> 24.8. Query settings </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-batch');" title="24.9. Batching properties"> 24.9. Batching properties </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-logging');" title="24.10. Statement logging and statistics"> 24.10. Statement logging and statistics </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-cache');" title="24.11. Cache Properties"> 24.11. Cache Properties </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-infinispan');" title="24.12. Infinispan properties"> 24.12. Infinispan properties </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-transactions');" title="24.13. Transactions properties"> 24.13. Transactions properties </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-multi-tenancy');" title="24.14. Multi-tenancy settings"> 24.14. Multi-tenancy settings </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-hbmddl');" title="24.15. Automatic schema generation"> 24.15. Automatic schema generation </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-exception-handling');" title="24.16. Exception handling"> 24.16. Exception handling </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-session-events');" title="24.17. Session events"> 24.17. Session events </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-jmx');" title="24.18. JMX settings"> 24.18. JMX settings </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-jacc');" title="24.19. JACC settings"> 24.19. JACC settings </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-classloader');" title="24.20. ClassLoaders properties"> 24.20. ClassLoaders properties </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-bootstrap');" title="24.21. Bootstrap properties"> 24.21. Bootstrap properties </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-misc');" title="24.22. Miscellaneous properties"> 24.22. Miscellaneous properties </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-envers');" title="24.23. Envers properties"> 24.23. Envers properties </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-spatial');" title="24.24. Spatial properties"> 24.24. Spatial properties </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#configurations-internal');" title="24.25. Internal properties"> 24.25. Internal properties </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#annotations');" title="25. Mapping annotations"> 25. Mapping annotations </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#annotations-jpa');" title="25.1. JPA annotations"> 25.1. JPA annotations </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#annotations-hibernate');" title="25.2. Hibernate annotations"> 25.2. Hibernate annotations </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#best-practices');" title="26. Performance Tuning and Best Practices"> 26. Performance Tuning and Best Practices </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#best-practices-schema');" title="26.1. Schema management"> 26.1. Schema management </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#best-practices-logging');" title="26.2. Logging"> 26.2. Logging </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#best-practices-jdbc-batching');" title="26.3. JDBC batching"> 26.3. JDBC batching </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#best-practices-mapping');" title="26.4. Mapping"> 26.4. Mapping </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#best-practices-inheritance');" title="26.5. Inheritance"> 26.5. Inheritance </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#best-practices-fetching');" title="26.6. Fetching"> 26.6. Fetching </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#best-practices-caching');" title="26.7. Caching"> 26.7. Caching </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#appendix-legacy-bootstrap');" title="27. Legacy Bootstrapping"> 27. Legacy Bootstrapping </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_migration');" title="28. Migration"> 28. Migration </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#appendix-legacy-domain-model');" title="29. Legacy Domain Model"> 29. Legacy Domain Model </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#appendix-legacy-criteria');" title="30. Legacy Hibernate Criteria Queries"> 30. Legacy Hibernate Criteria Queries </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-creating');" title="30.1. Creating a Criteria instance"> 30.1. Creating a Criteria instance </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-entity-name');" title="30.2. JPA vs. Hibernate entity name"> 30.2. JPA vs. Hibernate entity name </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-narrowing');" title="30.3. Narrowing the result set"> 30.3. Narrowing the result set </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-ordering');" title="30.4. Ordering the results"> 30.4. Ordering the results </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-associations');" title="30.5. Associations"> 30.5. Associations </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-dynamicfetching');" title="30.6. Dynamic association fetching"> 30.6. Dynamic association fetching </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-components');" title="30.7. Components"> 30.7. Components </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-collections');" title="30.8. Collections"> 30.8. Collections </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-examples');" title="30.9. Example queries"> 30.9. Example queries </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-projection');" title="30.10. Projections, aggregation and grouping"> 30.10. Projections, aggregation and grouping </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#criteria-detachedqueries');" title="30.11. Detached queries and subqueries"> 30.11. Detached queries and subqueries </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#query-criteria-naturalid');" title="30.12. Queries by natural identifier"> 30.12. Queries by natural identifier </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#appendix-legacy-native-queries');" title="31. Legacy Hibernate Native Queries"> 31. Legacy Hibernate Native Queries </a>
<ul class="articles">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#legacy-sql-named-queries');" title="31.1. Legacy named SQL queries"> 31.1. Legacy named SQL queries </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#legacy-propertyresults');" title="31.2. Legacy return-property to explicitly specify column/alias names"> 31.2. Legacy return-property to explicitly specify column/alias names </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#legacy-sp_query');" title="31.3. Legacy stored procedures for querying"> 31.3. Legacy stored procedures for querying </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#legacy-sql-limits-storedprocedures');" title="31.4. Legacy rules/limitations for using stored procedures"> 31.4. Legacy rules/limitations for using stored procedures </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#legacy-sql-cud');" title="31.5. Legacy custom SQL for create, update and delete"> 31.5. Legacy custom SQL for create, update and delete </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#legacy-sql-load');" title="31.6. Legacy custom SQL for loading"> 31.6. Legacy custom SQL for loading </a> </li>
</ul> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/hibernate-orm/5.4/reference/hibernate_user_guide.html#_references');" title="32. References"> 32. References </a> </li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<header class="book-header">
<div class="dropdown pull-right js-toolbar-action">
<a class="btn toggle-dropdown" aria-label="Language" href="#">
<i class="fa fa-globe"></i>
</a>
<div class="dropdown-menu dropdown-left">
<div class="dropdown-caret"><span class="caret-outer"></span><span class="caret-inner"></span></div>
<div class="buttons">
<button class="button size-1" onclick="changeLang('zh_CN')">中文</button>
</div>
<div class="buttons">
<button class="button size-1" onclick="changeLang('en_US')">English</button>
</div>
</div>
</div>
<a class="btn pull-right js-toolbar-action non-mobile" aria-label="Sign up" href="register.html">
<i class="fa fa-sign-in"></i> <span>注册</span>
</a>
<a class="btn pull-right js-toolbar-action non-mobile" aria-label="Sign in" href="register.html">
<i class="fa fa-sign-in"></i>
<span>登录</span>
</a>
<a class="btn pull-left js-toolbar-action btn-summary" href="#"><i class="fa fa-align-justify"></i></a>
<div class="dropdown pull-left font-settings js-toolbar-action">
<a class="btn toggle-dropdown" aria-label="Font Settings" href="#">
<i class="fa fa-font"></i>
</a>
<div class="dropdown-menu dropdown-right">
<div class="dropdown-caret"><span class="caret-outer"></span><span class="caret-inner"></span></div>
<div class="buttons">
<button class="button size-2 font-reduce">A</button>
<button class="button size-2 font-enlarge">A</button>
</div>
<div class="buttons">
<button class="button size-2 family-serif">Serif</button>
<button class="button size-2 family-sans">Sans</button>
</div>
<div class="buttons">
<button class="button size-3 theme-white">White</button>
<button class="button size-3 theme-sepia">Sepia</button>
<button class="button size-3 theme-night">Night</button>
</div>
</div>
</div>
<a class="btn pull-left js-toolbar-action non-mobile" aria-label="Home" href="en.html">
<i class="fa fa-home"></i> <span>首页</span>
</a>
<a class="btn pull-left js-toolbar-action non-mobile" aria-label="Guide" href="javascript:window.open('https://www.javadoc.org/');">
<i class="fa fa-book"></i> <span>API Docs</span>
</a>
<a class="btn pull-left js-toolbar-action non-mobile" aria-label="Tools" href="index37.html">
<i class="fa fa-gears"></i> <span>工具</span>
</a>
<div class="dropdown pull-left js-toolbar-action mobile">
<a class="btn toggle-dropdown" aria-label="Language" href="#">
<i class="fa fa-chevron-down"></i>
</a>
<div class="dropdown-menu dropdown-right">
<div class="dropdown-caret"><span class="caret-outer"></span><span class="caret-inner"></span></div>
<div class="buttons">
<a class="button size-1" aria-label="Home" href="en.html">
<i class="fa fa-home"></i> <span>首页</span>
</a>
</div>
<div class="buttons">
<a class="button size-1" aria-label="Guide" href="javascript:window.open('https://www.javadoc.org/');">
<i class="fa fa-book"></i> <span>API Docs</span>
</a>
</div>
<div class="buttons">
<a class="button size-1" aria-label="Tools" href="index37.html">
<i class="fa fa-gears"></i> <span>工具</span>
</a>
</div>
</div>
</div>
<div id="autocomplete" class="pull-right"></div>
<span id="toolbar-title"></span>
</header>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal markdown-section">
<div id="content">
<h1>Hibernate ORM 5.4.18.Final User Guide</h1>
<div><ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-6108808167664152" data-ad-slot="6964403648"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></div>
<div><div class="sect1">
<h2 id="preface"><a class="anchor" href="#preface"></a>Preface</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Working with both Object-Oriented software and Relational Databases can be cumbersome and time-consuming. Development costs are significantly higher due to a paradigm mismatch between how data is represented in objects versus relational databases. Hibernate is an Object/Relational Mapping solution for Java environments. The term <a href="javascript:window.open('https://en.wikipedia.org/wiki/Object-relational_mapping');" target="_blank" rel="noopener noreferrer">Object/Relational Mapping <i class="fa fa-external-link"></i></a> refers to the technique of mapping data from an object model representation to a relational data model representation (and vice versa).</p>
</div>
<div class="paragraph">
<p>Hibernate not only takes care of the mapping from Java classes to database tables (and from Java data types to SQL data types), but also provides data query and retrieval facilities. It can significantly reduce development time otherwise spent with manual data handling in SQL and JDBC. Hibernate’s design goal is to relieve the developer from 95% of common data persistence-related programming tasks by eliminating the need for manual, hand-crafted data processing using SQL and JDBC. However, unlike many other persistence solutions, Hibernate does not hide the power of SQL from you and guarantees that your investment in relational technology and knowledge is as valid as always.</p>
</div>
<div class="paragraph">
<p>Hibernate may not be the best solution for data-centric applications that only use stored-procedures to implement the business logic in the database, it is most useful with object-oriented domain models and business logic in the Java-based middle-tier. However, Hibernate can certainly help you to remove or encapsulate vendor-specific SQL code and will help with the common task of result set translation from a tabular representation to a graph of objects.</p>
</div>
<div class="sect2">
<h3 id="_get_involved"><a class="anchor" href="#_get_involved"></a>Get Involved</h3>
<div class="ulist">
<ul>
<li> <p>Use Hibernate and report any bugs or issues you find. See <a href="javascript:window.open('http://hibernate.org/issuetracker');" target="_blank" rel="noopener noreferrer">Issue Tracker <i class="fa fa-external-link"></i></a> for details.</p> </li>
<li> <p>Try your hand at fixing some bugs or implementing enhancements. Again, see <a href="javascript:window.open('http://hibernate.org/issuetracker');" target="_blank" rel="noopener noreferrer">Issue Tracker <i class="fa fa-external-link"></i></a>.</p> </li>
<li> <p>Engage with the community using mailing lists, forums, IRC, or other ways listed in the <a href="javascript:window.open('http://hibernate.org/community');" target="_blank" rel="noopener noreferrer">Community section <i class="fa fa-external-link"></i></a>.</p> </li>
<li> <p>Help improve or translate this documentation. Contact us on the developer mailing list if you have interest.</p> </li>
<li> <p>Spread the word. Let the rest of your organization know about the benefits of Hibernate.</p> </li>
</ul>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_system_requirements"><a class="anchor" href="#_system_requirements"></a>System Requirements </h2>
<div class="sectionbody">
<div class="paragraph">
<p>Hibernate 5.2 and later versions require at least Java 1.8 and JDBC 4.2.</p>
</div>
<div class="paragraph">
<p>Hibernate 5.1 and older versions require at least Java 1.6 and JDBC 4.0.</p>
</div>
<div class="admonitionblock tip">
<table>
<tbody>
<tr>
<td class="icon"> <i class="fa icon-tip" title="Tip"></i> </td>
<td class="content">
<div class="paragraph">
<p>When building Hibernate 5.1 or older from sources, you need Java 1.7 due to a bug in the JDK 1.6 compiler.</p>
</div> </td>
</tr>
</tbody>
</table>
</div>
<div class="sect2">
<h3 id="_getting_started_guide"><a class="anchor" href="#_getting_started_guide"></a>Getting Started Guide</h3>
<div class="paragraph">
<p>New users may want to first look through the <a href="javascript:window.open('https://docs.jboss.org/hibernate/orm/5.4/quickstart/html_single/');" target="_blank" rel="noopener noreferrer">Hibernate Getting Started Guide <i class="fa fa-external-link"></i></a> for basic information as well as tutorials. There is also a series of <a href="javascript:window.open('http://docs.jboss.org/hibernate/orm/5.4/topical/html_single/');" target="_blank" rel="noopener noreferrer">topical guides <i class="fa fa-external-link"></i></a> providing deep dives into various topics.</p>
</div>
<div class="admonitionblock note">
<table>
<tbody>
<tr>
<td class="icon"> <i class="fa icon-note" title="Note"></i> </td>
<td class="content">
<div class="paragraph">
<p>While having a strong background in SQL is not required to use Hibernate, it certainly helps a lot because it all boils down to SQL statements. Probably even more important is an understanding of data modeling principles. You might want to consider these resources as a good starting point:</p>
</div>
<div class="ulist">
<ul>
<li> <p><a href="javascript:window.open('https://en.wikipedia.org/wiki/Data_modeling');" target="_blank" rel="noopener noreferrer">Data modeling Wikipedia definition <i class="fa fa-external-link"></i></a></p> </li>
<li> <p><a href="javascript:window.open('http://www.agiledata.org/essays/dataModeling101.html');" target="_blank" rel="noopener noreferrer">Data Modeling 101 <i class="fa fa-external-link"></i></a></p> </li>
</ul>
</div>
<div class="paragraph">
<p>Understanding the basics of transactions and design patterns such as <em>Unit of Work</em> (<a href="#PoEAA">PoEAA</a>) or <em>Application Transaction</em> are important as well. These topics will be discussed in the documentation, but a prior understanding will certainly help.</p>
</div> </td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="architecture"><a class="anchor" href="#architecture"></a>1. Architecture</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="architecture-overview"><a class="anchor" href="#architecture-overview"></a>1.1. Overview </h3>
<div class="paragraph">
<p><span class="image"><img src="static/picture/data_access_layers.svg" alt="Data Access Layers"></span> </p>
</div>
<div class="paragraph">
<p>Hibernate, as an ORM solution, effectively "sits between" the Java application data access layer and the Relational Database, as can be seen in the diagram above. The Java application makes use of the Hibernate APIs to load, store, query, etc. its domain data. Here we will introduce the essential Hibernate APIs. This will be a brief introduction; we will discuss these contracts in detail later.</p>
</div>
<div class="paragraph">
<p>As a JPA provider, Hibernate implements the Java Persistence API specifications and the association between JPA interfaces and Hibernate specific implementations can be visualized in the following diagram:</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="static/picture/JPA_Hibernate.svg" alt="image"></span> </p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">
SessionFactory (
<code class="notranslate">org.hibernate.SessionFactory</code>)
</dt>
<dd>
<p>A thread-safe (and immutable) representation of the mapping of the application domain model to a database. Acts as a factory for <code class="notranslate">org.hibernate.Session</code> instances. The <code class="notranslate">EntityManagerFactory</code> is the JPA equivalent of a <code class="notranslate">SessionFactory</code> and basically, those two converge into the same <code class="notranslate">SessionFactory</code> implementation.</p>
<div class="paragraph">
<p>A <code class="notranslate">SessionFactory</code> is very expensive to create, so, for any given database, the application should have only one associated <code class="notranslate">SessionFactory</code>. The <code class="notranslate">SessionFactory</code> maintains services that Hibernate uses across all <code class="notranslate">Session(s)</code> such as second level caches, connection pools, transaction system integrations, etc. </p>
</div>
</dd>
<dt class="hdlist1">
Session (
<code class="notranslate">org.hibernate.Session</code>)
</dt>
<dd>
<p>A single-threaded, short-lived object conceptually modeling a "Unit of Work" (<a href="#PoEAA">PoEAA</a>). In JPA nomenclature, the <code class="notranslate">Session</code> is represented by an <code class="notranslate">EntityManager</code>.</p>
<div class="paragraph">
<p>Behind the scenes, the Hibernate <code class="notranslate">Session</code> wraps a JDBC <code class="notranslate">java.sql.Connection</code> and acts as a factory for <code class="notranslate">org.hibernate.Transaction</code> instances. It maintains a generally "repeatable read" persistence context (first level cache) of the application domain model.</p>
</div>
</dd>
<dt class="hdlist1">
Transaction (
<code class="notranslate">org.hibernate.Transaction</code>)
</dt>
<dd>
<p>A single-threaded, short-lived object used by the application to demarcate individual physical transaction boundaries. <code class="notranslate">EntityTransaction</code> is the JPA equivalent and both act as an abstraction API to isolate the application from the underlying transaction system in use (JDBC or JTA).</p>
</dd>
</dl>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="domain-model"><a class="anchor" href="#domain-model"></a>2. Domain Model</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The term <a href="javascript:window.open('https://en.wikipedia.org/wiki/Domain_model');" target="_blank" rel="noopener noreferrer">domain model <i class="fa fa-external-link"></i></a> comes from the realm of data modeling. It is the model that ultimately describes the <a href="javascript:window.open('https://en.wikipedia.org/wiki/Problem_domain');" target="_blank" rel="noopener noreferrer">problem domain <i class="fa fa-external-link"></i></a> you are working in. Sometimes you will also hear the term <em>persistent classes</em>.</p>
</div>
<div class="paragraph">
<p>Ultimately the application domain model is the central character in an ORM. They make up the classes you wish to map. Hibernate works best if these classes follow the Plain Old Java Object (POJO) / JavaBean programming model. However, none of these rules are hard requirements. Indeed, Hibernate assumes very little about the nature of your persistent objects. You can express a domain model in other ways (using trees of <code class="notranslate">java.util.Map</code> instances, for example).</p>
</div>
<div class="paragraph">
<p>Historically applications using Hibernate would have used its proprietary XML mapping file format for this purpose. With the coming of JPA, most of this information is now defined in a way that is portable across ORM/JPA providers using annotations (and/or standardized XML format). This chapter will focus on JPA mapping where possible. For Hibernate mapping features not supported by JPA we will prefer Hibernate extension annotations.</p>
</div>
<div class="sect2">
<h3 id="mapping-types"><a class="anchor" href="#mapping-types"></a>2.1. Mapping types</h3>
<div class="paragraph">
<p>Hibernate understands both the Java and JDBC representations of application data. The ability to read/write this data from/to the database is the function of a Hibernate <em>type</em>. A type, in this usage, is an implementation of the <code class="notranslate">org.hibernate.type.Type</code> interface. This Hibernate type also describes various behavioral aspects of the Java type such as how to check for equality, how to clone values, etc.</p>
</div>
<div class="admonitionblock note">
<table>
<tbody>
<tr>
<td class="icon"> <i class="fa icon-note" title="Note"></i> </td>
<td class="content">
<div class="title">
Usage of the word
<em>type</em>
</div>
<div class="paragraph">
<p>The Hibernate type is neither a Java type nor a SQL data type. It provides information about mapping a Java type to an SQL type as well as how to persist and fetch a given Java type to and from a relational database.</p>
</div>
<div class="paragraph">
<p>When you encounter the term type in discussions of Hibernate, it may refer to the Java type, the JDBC type, or the Hibernate type, depending on the context.</p>
</div> </td>
</tr>
</tbody>
</table>
</div>
<div class="paragraph">
<p>To help understand the type categorizations, let’s look at a simple table and domain model that we wish to map.</p>
</div>
<div id="mapping-types-basic-example" class="exampleblock">
<div class="title">
Example 1. A simple table and domain model
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-SQL" data-lang="SQL">create table Contact (
    id integer not null,
    first varchar(255),
    last varchar(255),
    middle varchar(255),
    notes varchar(255),
    starred boolean not null,
    website varchar(255),
    primary key (id)
)</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">@Entity(name = "Contact")
public static class Contact {

	@Id
	private Integer id;

	private Name name;

	private String notes;

	private URL website;

	private boolean starred;

	//Getters and setters are omitted for brevity
}

@Embeddable
public class Name {

	private String first;

	private String middle;

	private String last;

	// getters and setters omitted
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>In the broadest sense, Hibernate categorizes types into two groups:</p>
</div>
<div class="ulist">
<ul>
<li> <p><a href="#categorization-value">Value types</a></p> </li>
<li> <p><a href="#categorization-entity">Entity types</a></p> </li>
</ul>
</div>
<div class="sect3">
<h4 id="categorization-value"><a class="anchor" href="#categorization-value"></a>2.1.1. Value types</h4>
<div class="paragraph">
<p>A value type is a piece of data that does not define its own lifecycle. It is, in effect, owned by an entity, which defines its lifecycle.</p>
</div>
<div class="paragraph">
<p>Looked at another way, all the state of an entity is made up entirely of value types. These state fields or JavaBean properties are termed <em>persistent attributes</em>. The persistent attributes of the <code class="notranslate">Contact</code> class are value types.</p>
</div>
<div class="paragraph">
<p>Value types are further classified into three sub-categories:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">
Basic types
</dt>
<dd>
<p>in mapping the <code class="notranslate">Contact</code> table, all attributes except for name would be basic types. Basic types are discussed in detail in <a href="#basic"><em>Basic types</em></a></p>
</dd>
<dt class="hdlist1">
Embeddable types
</dt>
<dd>
<p>the <code class="notranslate">name</code> attribute is an example of an embeddable type, which is discussed in details in <a href="#embeddables"><em>Embeddable types</em></a> </p>
</dd>
<dt class="hdlist1">
<strong>Collection</strong> types
</dt>
<dd>
<p>although not featured in the aforementioned example, collection types are also a distinct category among value types. Collection types are further discussed in <a href="#collections"><em>Collections</em></a></p>
</dd>
</dl>
</div>
</div>
<div class="sect3">
<h4 id="categorization-entity"><a class="anchor" href="#categorization-entity"></a>2.1.2. Entity types</h4>
<div class="paragraph">
<p>Entities, by nature of their unique identifier, exist independently of other objects whereas values do not. Entities are domain model classes which correlate to rows in a database table, using a unique identifier. Because of the requirement for a unique identifier, entities exist independently and define their own lifecycle. The <code class="notranslate">Contact</code> class itself would be an example of an entity.</p>
</div>
<div class="paragraph">
<p>Mapping entities is discussed in detail in <a href="#entity"><em>Entity types</em></a>.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="naming"><a class="anchor" href="#naming"></a>2.2. Naming strategies</h3>
<div class="paragraph">
<p>Part of the mapping of an object model to the relational database is mapping names from the object model to the corresponding database names. Hibernate looks at this as 2-stage process:</p>
</div>
<div class="ulist">
<ul>
<li> <p>The first stage is determining a proper logical name from the domain model mapping. A logical name can be either explicitly specified by the user (e.g., using <code class="notranslate">@Column</code> or <code class="notranslate">@Table</code>) or it can be implicitly determined by Hibernate through an <a href="#ImplicitNamingStrategy">ImplicitNamingStrategy</a> contract.</p> </li>
<li> <p>Second is the resolving of this logical name to a physical name which is defined by the <a href="#PhysicalNamingStrategy">PhysicalNamingStrategy</a> contract. </p> </li>
</ul>
</div>
<div class="admonitionblock note">
<table>
<tbody>
<tr>
<td class="icon"> <i class="fa icon-note" title="Note"></i> </td>
<td class="content">
<div class="title">
Historical NamingStrategy contract
</div>
<div class="paragraph">
<p>Historically Hibernate defined just a single <code class="notranslate">org.hibernate.cfg.NamingStrategy</code>. That singular NamingStrategy contract actually combined the separate concerns that are now modeled individually as ImplicitNamingStrategy and PhysicalNamingStrategy.</p>
</div>
<div class="paragraph">
<p>Also, the NamingStrategy contract was often not flexible enough to properly apply a given naming "rule", either because the API lacked the information to decide or because the API was honestly not well defined as it grew.</p>
</div>
<div class="paragraph">
<p>Due to these limitation, <code class="notranslate">org.hibernate.cfg.NamingStrategy</code> has been deprecated in favor of ImplicitNamingStrategy and PhysicalNamingStrategy.</p>
</div> </td>
</tr>
</tbody>
</table>
</div>
<div class="paragraph">
<p>At the core, the idea behind each naming strategy is to minimize the amount of repetitive information a developer must provide for mapping a domain model.</p>
</div>
<div class="admonitionblock note">
<table>
<tbody>
<tr>
<td class="icon"> <i class="fa icon-note" title="Note"></i> </td>
<td class="content">
<div class="title">
JPA Compatibility
</div>
<div class="paragraph">
<p>JPA defines inherent rules about implicit logical name determination. If JPA provider portability is a major concern, or if you really just like the JPA-defined implicit naming rules, be sure to stick with ImplicitNamingStrategyJpaCompliantImpl (the default).</p>
</div>
<div class="paragraph">
<p>Also, JPA defines no separation between logical and physical name. Following the JPA specification, the logical name <strong>is</strong> the physical name. If JPA provider portability is important, applications should prefer not to specify a PhysicalNamingStrategy.</p>
</div> </td>
</tr>
</tbody>
</table>
</div>
<div class="sect3">
<h4 id="ImplicitNamingStrategy"><a class="anchor" href="#ImplicitNamingStrategy"></a>2.2.1. ImplicitNamingStrategy</h4>
<div class="paragraph">
<p>When an entity does not explicitly name the database table that it maps to, we need to implicitly determine that table name. Or when a particular attribute does not explicitly name the database column that it maps to, we need to implicitly determine that column name. There are examples of the role of the <code class="notranslate">org.hibernate.boot.model.naming.ImplicitNamingStrategy</code> contract to determine a logical name when the mapping did not provide an explicit name.</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="static/picture/implicit_naming_strategy_diagram.svg" alt="Implicit Naming Strategy Diagram"></span> </p>
</div>
<div class="paragraph">
<p>Hibernate defines multiple ImplicitNamingStrategy implementations out-of-the-box. Applications are also free to plug in custom implementations.</p>
</div>
<div class="paragraph">
<p>There are multiple ways to specify the ImplicitNamingStrategy to use. First, applications can specify the implementation using the <code class="notranslate">hibernate.implicit_naming_strategy</code> configuration setting which accepts: </p>
</div>
<div class="ulist">
<ul>
<li> <p>pre-defined "short names" for the out-of-the-box implementations</p>
<div class="dlist">
<dl>
<dt class="hdlist1">
<code class="notranslate">default</code>
</dt>
<dd>
<p>for <code class="notranslate">org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl</code> - an alias for <code class="notranslate">jpa</code></p>
</dd>
<dt class="hdlist1">
<code class="notranslate">jpa</code>
</dt>
<dd>
<p>for <code class="notranslate">org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl</code> - the JPA 2.0 compliant naming strategy</p>
</dd>
<dt class="hdlist1">
<code class="notranslate">legacy-hbm</code>
</dt>
<dd>
<p>for <code class="notranslate">org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl</code> - compliant with the original Hibernate NamingStrategy</p>
</dd>
<dt class="hdlist1">
<code class="notranslate">legacy-jpa</code>
</dt>
<dd>
<p>for <code class="notranslate">org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl</code> - compliant with the legacy NamingStrategy developed for JPA 1.0, which was unfortunately unclear in many respects regarding implicit naming rules</p>
</dd>
<dt class="hdlist1">
<code class="notranslate">component-path</code>
</dt>
<dd>
<p>for <code class="notranslate">org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl</code> - mostly follows <code class="notranslate">ImplicitNamingStrategyJpaCompliantImpl</code> rules, except that it uses the full composite paths, as opposed to just the ending property part</p>
</dd>
</dl>
</div> </li>
<li> <p>reference to a Class that implements the <code class="notranslate">org.hibernate.boot.model.naming.ImplicitNamingStrategy</code> contract </p> </li>
<li> <p>FQN of a class that implements the <code class="notranslate">org.hibernate.boot.model.naming.ImplicitNamingStrategy</code> contract </p> </li>
</ul>
</div>
<div class="paragraph">
<p>Secondly, applications and integrations can leverage <code class="notranslate">org.hibernate.boot.MetadataBuilder#applyImplicitNamingStrategy</code> to specify the ImplicitNamingStrategy to use. See <a href="#bootstrap">Bootstrap</a> for additional details on bootstrapping.</p>
</div>
</div>
<div class="sect3">
<h4 id="PhysicalNamingStrategy"><a class="anchor" href="#PhysicalNamingStrategy"></a>2.2.2. PhysicalNamingStrategy</h4>
<div class="paragraph">
<p>Many organizations define rules around the naming of database objects (tables, columns, foreign keys, etc). The idea of a PhysicalNamingStrategy is to help implement such naming rules without having to hard-code them into the mapping via explicit names.</p>
</div>
<div class="paragraph">
<p>While the purpose of an ImplicitNamingStrategy is to determine that an attribute named <code class="notranslate">accountNumber</code> maps to a logical column name of <code class="notranslate">accountNumber</code> when not explicitly specified, the purpose of a PhysicalNamingStrategy would be, for example, to say that the physical column name should instead be abbreviated <code class="notranslate">acct_num</code>.</p>
</div>
<div class="admonitionblock note">
<table>
<tbody>
<tr>
<td class="icon"> <i class="fa icon-note" title="Note"></i> </td>
<td class="content">
<div class="paragraph">
<p>It is true that the resolution to <code class="notranslate">acct_num</code> could have been handled using an <code class="notranslate">ImplicitNamingStrategy</code> in this case.</p>
</div>
<div class="paragraph">
<p>But the point here is the separation of concerns. The <code class="notranslate">PhysicalNamingStrategy</code> will be applied regardless of whether the attribute explicitly specified the column name or whether we determined that implicitly. The <code class="notranslate">ImplicitNamingStrategy</code> would only be applied if an explicit name was not given. So, it all depends on needs and intent.</p>
</div> </td>
</tr>
</tbody>
</table>
</div>
<div class="paragraph">
<p>The default implementation is to simply use the logical name as the physical name. However applications and integrations can define custom implementations of this PhysicalNamingStrategy contract. Here is an example PhysicalNamingStrategy for a fictitious company named Acme Corp whose naming standards are to:</p>
</div>
<div class="ulist">
<ul>
<li> <p>prefer underscore-delimited words rather than camel casing</p> </li>
<li> <p>replace certain words with standard abbreviations</p> </li>
</ul>
</div>
<div class="exampleblock">
<div class="title">
Example 2. Example PhysicalNamingStrategy implementation
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-java" data-lang="java">/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or &lt;http://www.gnu.org/licenses/lgpl-2.1.html&gt;.
 */
package org.hibernate.userguide.naming;

import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;

import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;

import org.apache.commons.lang3.StringUtils;

/**
 * An example PhysicalNamingStrategy that implements database object naming standards
 * for our fictitious company Acme Corp.
 * &lt;p/&gt;
 * In general Acme Corp prefers underscore-delimited words rather than camel casing.
 * &lt;p/&gt;
 * Additionally standards call for the replacement of certain words with abbreviations.
 *
 * @author Steve Ebersole
 */
public class AcmeCorpPhysicalNamingStrategy implements PhysicalNamingStrategy {
	private static final Map&lt;String,String&gt; ABBREVIATIONS = buildAbbreviationMap();

	@Override
	public Identifier toPhysicalCatalogName(Identifier name, JdbcEnvironment jdbcEnvironment) {
		// Acme naming standards do not apply to catalog names
		return name;
	}

	@Override
	public Identifier toPhysicalSchemaName(Identifier name, JdbcEnvironment jdbcEnvironment) {
		// Acme naming standards do not apply to schema names
		return name;
	}

	@Override
	public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment jdbcEnvironment) {
		final List&lt;String&gt; parts = splitAndReplace( name.getText() );
		return jdbcEnvironment.getIdentifierHelper().toIdentifier(
				join( parts ),
				name.isQuoted()
		);
	}

	@Override
	public Identifier toPhysicalSequenceName(Identifier name, JdbcEnvironment jdbcEnvironment) {
		final LinkedList&lt;String&gt; parts = splitAndReplace( name.getText() );
		// Acme Corp says all sequences should end with _seq
		if ( !"seq".equalsIgnoreCase( parts.getLast() ) ) {
			parts.add( "seq" );
		}
		return jdbcEnvironment.getIdentifierHelper().toIdentifier(
				join( parts ),
				name.isQuoted()
		);
	}

	@Override
	public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment jdbcEnvironment) {
		final List&lt;String&gt; parts = splitAndReplace( name.getText() );
		return jdbcEnvironment.getIdentifierHelper().toIdentifier(
				join( parts ),
				name.isQuoted()
		);
	}

	private static Map&lt;String, String&gt; buildAbbreviationMap() {
		TreeMap&lt;String,String&gt; abbreviationMap = new TreeMap&lt;&gt; ( String.CASE_INSENSITIVE_ORDER );
		abbreviationMap.put( "account", "acct" );
		abbreviationMap.put( "number", "num" );
		return abbreviationMap;
	}

	private LinkedList&lt;String&gt; splitAndReplace(String name) {
		LinkedList&lt;String&gt; result = new LinkedList&lt;&gt;();
		for ( String part : StringUtils.splitByCharacterTypeCamelCase( name ) ) {
			if ( part == null || part.trim().isEmpty() ) {
				// skip null and space
				continue;
			}
			part = applyAbbreviationReplacement( part );
			result.add( part.toLowerCase( Locale.ROOT ) );
		}
		return result;
	}

	private String applyAbbreviationReplacement(String word) {
		if ( ABBREVIATIONS.containsKey( word ) ) {
			return ABBREVIATIONS.get( word );
		}

		return word;
	}

	private String join(List&lt;String&gt; parts) {
		boolean firstPass = true;
		String separator = "";
		StringBuilder joined = new StringBuilder();
		for ( String part : parts ) {
			joined.append( separator ).append( part );
			if ( firstPass ) {
				firstPass = false;
				separator = "_";
			}
		}
		return joined.toString();
	}
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>There are multiple ways to specify the PhysicalNamingStrategy to use. First, applications can specify the implementation using the <code class="notranslate">hibernate.physical_naming_strategy</code> configuration setting which accepts: </p>
</div>
<div class="ulist">
<ul>
<li> <p>reference to a Class that implements the <code class="notranslate">org.hibernate.boot.model.naming.PhysicalNamingStrategy</code> contract </p> </li>
<li> <p>FQN of a class that implements the <code class="notranslate">org.hibernate.boot.model.naming.PhysicalNamingStrategy</code> contract </p> </li>
</ul>
</div>
<div class="paragraph">
<p>Secondly, applications and integrations can leverage <code class="notranslate">org.hibernate.boot.MetadataBuilder#applyPhysicalNamingStrategy</code>. See <a href="#bootstrap">Bootstrap</a> for additional details on bootstrapping.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="basic"><a class="anchor" href="#basic"></a>2.3. Basic types</h3>
<div class="paragraph">
 <p>Basic value types usually map a single database column, to a single, non-aggregated Java type. Hibernate provides a number of built-in basic types, which follow the natural mappings recommended by the JDBC specifications.</p>
</div>
<div class="paragraph">
<p>Internally Hibernate uses a registry of basic types when it needs to resolve a specific <code class="notranslate">org.hibernate.type.Type</code>.</p>
</div>
<div class="sect3">
<h4 id="basic-provided"><a class="anchor" href="#basic-provided"></a>2.3.1. Hibernate-provided BasicTypes</h4>
<table class="tableblock frame-all grid-all spread">
<caption class="title">
Table 1. Standard BasicTypes
</caption>
<colgroup>
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-middle">Hibernate type (org.hibernate.type package)</th>
<th class="tableblock halign-left valign-middle">JDBC type</th>
<th class="tableblock halign-left valign-middle">Java type</th>
<th class="tableblock halign-left valign-middle">BasicTypeRegistry key(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">StringType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">VARCHAR</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.lang.String</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">string, java.lang.String</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">MaterializedClob</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">CLOB</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.lang.String</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">materialized_clob</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TextType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">LONGVARCHAR</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.lang.String</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">text</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">CharacterType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">CHAR</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">char, java.lang.Character</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">character, char, java.lang.Character</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">BooleanType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">BOOLEAN</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">boolean, java.lang.Boolean</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">boolean, java.lang.Boolean</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">NumericBooleanType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">INTEGER, 0 is false, 1 is true</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">boolean, java.lang.Boolean</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">numeric_boolean</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">YesNoType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">CHAR, 'N'/'n' is false, 'Y'/'y' is true. The uppercase value is written to the database.</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">boolean, java.lang.Boolean</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">yes_no</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TrueFalseType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">CHAR, 'F'/'f' is false, 'T'/'t' is true. The uppercase value is written to the database.</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">boolean, java.lang.Boolean</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">true_false</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">ByteType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TINYINT</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">byte, java.lang.Byte</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">byte, java.lang.Byte</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">ShortType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">SMALLINT</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">short, java.lang.Short</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">short, java.lang.Short</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">IntegerType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">INTEGER</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">int, java.lang.Integer</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">integer, int, java.lang.Integer</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">LongType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">BIGINT</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">long, java.lang.Long</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">long, java.lang.Long</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">FloatType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">FLOAT</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">float, java.lang.Float</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">float, java.lang.Float</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">DoubleType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">DOUBLE</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">double, java.lang.Double</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">double, java.lang.Double</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">BigIntegerType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">NUMERIC</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.math.BigInteger</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">big_integer, java.math.BigInteger</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">BigDecimalType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">NUMERIC</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.math.BigDecimal</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">big_decimal, java.math.bigDecimal</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TimestampType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TIMESTAMP</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.util.Date</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">timestamp, java.sql.Timestamp, java.util.Date</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">DbTimestampType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TIMESTAMP</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.util.Date</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">dbtimestamp</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TimeType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TIME</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.util.Date</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">time, java.sql.Time</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">DateType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">DATE</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.util.Date</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">date, java.sql.Date</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">CalendarType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TIMESTAMP</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.util.Calendar</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">calendar, java.util.Calendar, java.util.GregorianCalendar</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">CalendarDateType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">DATE</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.util.Calendar</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">calendar_date</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">CalendarTimeType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TIME</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.util.Calendar</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">calendar_time</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">CurrencyType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">VARCHAR</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.util.Currency</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">currency, java.util.Currency</p> </td>
</tr>
<tr> 
<td class="tableblock halign-left valign-middle"> <p class="tableblock">LocaleType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">VARCHAR</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.util.Locale</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">locale, java.util.Locale</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TimeZoneType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">VARCHAR, using the TimeZone ID</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.util.TimeZone</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">timezone, java.util.TimeZone</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">UrlType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">VARCHAR</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.net.URL</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">url, java.net.URL</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">ClassType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">VARCHAR (class FQN)</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.lang.Class</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">class, java.lang.Class</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">BlobType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">BLOB</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.sql.Blob</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">blob, java.sql.Blob</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">ClobType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">CLOB</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.sql.Clob</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">clob, java.sql.Clob</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">BinaryType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">VARBINARY</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">byte[]</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">binary, byte[]</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">MaterializedBlobType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">BLOB</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">byte[]</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">materialized_blob</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">ImageType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">LONGVARBINARY</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">byte[]</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">image</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">WrapperBinaryType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">VARBINARY</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.lang.Byte[]</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">wrapper-binary, Byte[], java.lang.Byte[]</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">CharArrayType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">VARCHAR</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">char[]</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">characters, char[]</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">CharacterArrayType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">VARCHAR</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.lang.Character[]</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">wrapper-characters, Character[], java.lang.Character[] </p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">UUIDBinaryType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">BINARY</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.util.UUID</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">uuid-binary, java.util.UUID</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">UUIDCharType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">CHAR, can also read VARCHAR</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.util.UUID</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">uuid-char</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">PostgresUUIDType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">PostgreSQL UUID, through Types#OTHER, which complies to the PostgreSQL JDBC driver definition</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.util.UUID</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">pg-uuid</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">SerializableType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">VARBINARY</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">implementors of java.lang.Serializable</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">Unlike the other value types, multiple instances of this type are registered. It is registered once under java.io.Serializable, and registered under the specific java.io.Serializable implementation class names.</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">StringNVarcharType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">NVARCHAR</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.lang.String</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">nstring</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">NTextType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">LONGNVARCHAR</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.lang.String</p> </td>
 <td class="tableblock halign-left valign-middle"> <p class="tableblock">ntext</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">NClobType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">NCLOB</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.sql.NClob</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">nclob, java.sql.NClob</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">MaterializedNClobType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">NCLOB</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.lang.String</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">materialized_nclob</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">PrimitiveCharacterArrayNClobType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">NCHAR</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">char[]</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">N/A</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">CharacterNCharType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">NCHAR</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.lang.Character</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">ncharacter</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">CharacterArrayNClobType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">NCLOB</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.lang.Character[]</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">N/A</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">RowVersionType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">VARBINARY</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">byte[]</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">row_version</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">ObjectType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">VARCHAR</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">implementors of java.lang.Serializable</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">object, java.lang.Object</p> </td>
</tr>
</tbody>
</table>
<table class="tableblock frame-all grid-all spread">
<caption class="title">
Table 2. Java 8 BasicTypes
</caption>
<colgroup>
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-middle">Hibernate type (org.hibernate.type package)</th>
<th class="tableblock halign-left valign-middle">JDBC type</th>
<th class="tableblock halign-left valign-middle">Java type</th>
<th class="tableblock halign-left valign-middle">BasicTypeRegistry key(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">DurationType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">BIGINT</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.time.Duration</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">Duration, java.time.Duration</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">InstantType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TIMESTAMP</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.time.Instant</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">Instant, java.time.Instant</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">LocalDateTimeType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TIMESTAMP</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.time.LocalDateTime</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">LocalDateTime, java.time.LocalDateTime</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">LocalDateType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">DATE</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.time.LocalDate</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">LocalDate, java.time.LocalDate</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">LocalTimeType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TIME</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.time.LocalTime</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">LocalTime, java.time.LocalTime</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">OffsetDateTimeType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TIMESTAMP</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.time.OffsetDateTime</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">OffsetDateTime, java.time.OffsetDateTime</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">OffsetTimeType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TIME</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.time.OffsetTime</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">OffsetTime, java.time.OffsetTime</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">ZonedDateTimeType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">TIMESTAMP</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">java.time.ZonedDateTime</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">ZonedDateTime, java.time.ZonedDateTime</p> </td>
</tr>
</tbody>
</table>
<table class="tableblock frame-all grid-all spread">
<caption class="title">
Table 3. Hibernate Spatial BasicTypes
</caption>
<colgroup>
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-middle">Hibernate type (org.hibernate.spatial package)</th>
<th class="tableblock halign-left valign-middle">JDBC type</th>
<th class="tableblock halign-left valign-middle">Java type</th>
<th class="tableblock halign-left valign-middle">BasicTypeRegistry key(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">JTSGeometryType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">depends on the dialect</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">com.vividsolutions.jts.geom.Geometry</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">jts_geometry, and the class names of Geometry and its subclasses</p> </td>
</tr>
<tr>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">GeolatteGeometryType</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">depends on the dialect</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">org.geolatte.geom.Geometry</p> </td>
<td class="tableblock halign-left valign-middle"> <p class="tableblock">geolatte_geometry, and the class names of Geometry and its subclasses</p> </td>
</tr>
</tbody>
</table>
<div class="admonitionblock note">
<table>
<tbody>
<tr>
<td class="icon"> <i class="fa icon-note" title="Note"></i> </td>
<td class="content">
<div class="paragraph">
<p>To use the Hibernate Spatial types, you must add the <code class="notranslate">hibernate-spatial</code> dependency to your classpath <em>and</em> use an <code class="notranslate">org.hibernate.spatial.SpatialDialect</code> implementation.</p>
</div>
<div class="paragraph">
<p>See the <a href="#spatial">Spatial</a> chapter for more details. </p>
</div> </td>
</tr>
</tbody>
</table>
</div>
<div class="paragraph">
<p>These mappings are managed by a service inside Hibernate called the <code class="notranslate">org.hibernate.type.BasicTypeRegistry</code>, which essentially maintains a map of <code class="notranslate">org.hibernate.type.BasicType</code> (a <code class="notranslate">org.hibernate.type.Type</code> specialization) instances keyed by a name. That is the purpose of the "BasicTypeRegistry key(s)" column in the previous tables.</p>
</div>
</div>
<div class="sect3">
<h4 id="basic-annotation"><a class="anchor" href="#basic-annotation"></a>2.3.2. The <code class="notranslate">@Basic</code> annotation</h4>
<div class="paragraph">
<p>Strictly speaking, a basic type is denoted by the <code class="notranslate">javax.persistence.Basic</code> annotation. Generally speaking, the <code class="notranslate">@Basic</code> annotation can be ignored, as it is assumed by default. Both of the following examples are ultimately the same.</p>
</div>
<div id="basic-annotation-explicit-example" class="exampleblock">
<div class="title">
Example 3.
<code class="notranslate">@Basic</code> declared explicitly
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">@Entity(name = "Product")
public class Product {

	@Id
	@Basic
	private Integer id;

	@Basic
	private String sku;

	@Basic
	private String name;

	@Basic
	private String description;
}</code></pre>
</div>
</div>
</div>
</div>
<div id="basic-annotation-implicit-example" class="exampleblock">
<div class="title">
Example 4.
<code class="notranslate">@Basic</code> being implicitly implied
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">@Entity(name = "Product")
public class Product {

	@Id
	private Integer id;

	private String sku;

	private String name;

	private String description;
}</code></pre>
</div>
</div>
</div>
</div>
<div class="admonitionblock tip">
<table>
<tbody>
<tr>
<td class="icon"> <i class="fa icon-tip" title="Tip"></i> </td>
<td class="content">
<div class="paragraph">
<p>The JPA specification strictly limits the Java types that can be marked as basic to the following listing:</p>
</div>
<div class="ulist">
<ul>
<li> <p>Java primitive types (<code class="notranslate">boolean</code>, <code class="notranslate">int</code>, etc)</p> </li>
<li> <p>wrappers for the primitive types (<code class="notranslate">java.lang.Boolean</code>, <code class="notranslate">java.lang.Integer</code>, etc)</p> </li>
<li> <p><code class="notranslate">java.lang.String</code></p> </li>
<li> <p><code class="notranslate">java.math.BigInteger</code></p> </li>
<li> <p><code class="notranslate">java.math.BigDecimal</code></p> </li>
<li> <p><code class="notranslate">java.util.Date</code></p> </li>
<li> <p><code class="notranslate">java.util.Calendar</code></p> </li>
<li> <p><code class="notranslate">java.sql.Date</code></p> </li>
<li> <p><code class="notranslate">java.sql.Time</code></p> </li>
<li> <p><code class="notranslate">java.sql.Timestamp</code></p> </li>
<li> <p><code class="notranslate">byte[]</code> or <code class="notranslate">Byte[]</code></p> </li>
<li> <p><code class="notranslate">char[]</code> or <code class="notranslate">Character[]</code></p> </li>
<li> <p><code class="notranslate">enums</code></p> </li>
<li> <p>any other type that implements <code class="notranslate">Serializable</code> (JPA’s "support" for <code class="notranslate">Serializable</code> types is to directly serialize their state to the database).</p> </li>
</ul>
</div>
<div class="paragraph">
<p>If provider portability is a concern, you should stick to just these basic types.</p>
</div>
<div class="paragraph">
<p>Note that JPA 2.1 introduced the <code class="notranslate">javax.persistence.AttributeConverter</code> contract to help alleviate some of these concerns. See <a href="#basic-jpa-convert">JPA 2.1 AttributeConverters</a> for more on this topic.</p>
</div> </td>
</tr>
</tbody>
</table>
</div>
<div class="paragraph">
<p>The <code class="notranslate">@Basic</code> annotation defines 2 attributes.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">
<code class="notranslate">optional</code> - boolean (defaults to true)
</dt>
<dd>
<p>Defines whether this attribute allows nulls. JPA defines this as "a hint", which essentially means that its effect is specifically required. As long as the type is not primitive, Hibernate takes this to mean that the underlying column should be <code class="notranslate">NULLABLE</code>.</p>
</dd>
<dt class="hdlist1">
<code class="notranslate">fetch</code> - FetchType (defaults to EAGER)
</dt>
<dd>
<p>Defines whether this attribute should be fetched eagerly or lazily. JPA says that EAGER is a requirement to the provider (Hibernate) that the value should be fetched when the owner is fetched, while LAZY is merely a hint that the value is fetched when the attribute is accessed. Hibernate ignores this setting for basic types unless you are using bytecode enhancement. See the <a href="#BytecodeEnhancement">Bytecode Enhancement</a> for additional information on fetching and on bytecode enhancement.</p>
</dd>
</dl>
</div>
</div>
<div class="sect3">
<h4 id="basic-column-annotation"><a class="anchor" href="#basic-column-annotation"></a>2.3.3. The <code class="notranslate">@Column</code> annotation</h4>
<div class="paragraph">
<p>JPA defines rules for implicitly determining the name of tables and columns. For a detailed discussion of implicit naming see <a href="#naming">Naming strategies</a>. </p>
</div>
<div class="paragraph">
<p>For basic type attributes, the implicit naming rule is that the column name is the same as the attribute name. If that implicit naming rule does not meet your requirements, you can explicitly tell Hibernate (and other providers) the column name to use.</p>
</div>
<div id="basic-annotation-explicit-column-example" class="exampleblock">
<div class="title">
Example 5. Explicit column naming
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">@Entity(name = "Product")
public class Product {

	@Id
	private Integer id;

	private String sku;

	private String name;

	@Column( name = "NOTES" )
	private String description;
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>Here we use <code class="notranslate">@Column</code> to explicitly map the <code class="notranslate">description</code> attribute to the <code class="notranslate">NOTES</code> column, as opposed to the implicit column name <code class="notranslate">description</code>.</p>
</div>
<div class="paragraph">
<p>The <code class="notranslate">@Column</code> annotation defines other mapping information as well. See its Javadocs for details.</p>
</div>
</div>
<div class="sect3">
<h4 id="basic-registry"><a class="anchor" href="#basic-registry"></a>2.3.4. BasicTypeRegistry</h4>
<div class="paragraph">
<p>We said before that a Hibernate type is not a Java type, nor an SQL type, but that it understands both and performs the marshalling between them. But looking at the basic type mappings from the previous examples, how did Hibernate know to use its <code class="notranslate">org.hibernate.type.StringType</code> for mapping for <code class="notranslate">java.lang.String</code> attributes, or its <code class="notranslate">org.hibernate.type.IntegerType</code> for mapping <code class="notranslate">java.lang.Integer</code> attributes?</p>
</div>
<div class="paragraph">
<p>The answer lies in a service inside Hibernate called the <code class="notranslate">org.hibernate.type.BasicTypeRegistry</code>, which essentially maintains a map of <code class="notranslate">org.hibernate.type.BasicType</code> (an <code class="notranslate">org.hibernate.type.Type</code> specialization) instances keyed by a name.</p>
</div>
<div class="paragraph">
<p>We will see later, in the <a href="#basic-type-annotation">Explicit BasicTypes</a> section, that we can explicitly tell Hibernate which BasicType to use for a particular attribute. But first, let’s explore how implicit resolution works and how applications can adjust the implicit resolution.</p>
</div>
<div class="admonitionblock note">
<table>
<tbody>
<tr>
<td class="icon"> <i class="fa icon-note" title="Note"></i> </td>
<td class="content">
<div class="paragraph">
<p>A thorough discussion of <code class="notranslate">BasicTypeRegistry</code> and all the different ways to contribute types is beyond the scope of this documentation.</p>
</div>
<div class="paragraph">
<p>Please see the <a href="javascript:window.open('http://docs.jboss.org/hibernate/orm/5.4/integrationguide/html_single/Hibernate_Integration_Guide.html');" target="_blank" rel="noopener noreferrer">Integration Guide <i class="fa fa-external-link"></i></a> for complete details.</p>
</div> </td>
</tr>
</tbody>
</table>
</div>
<div class="paragraph">
<p>As an example, take a String attribute such as we saw before with Product#sku. Since there was no explicit type mapping, Hibernate looks to the <code class="notranslate">BasicTypeRegistry</code> to find the registered mapping for <code class="notranslate">java.lang.String</code>. This goes back to the "BasicTypeRegistry key(s)" column we saw in the tables at the start of this chapter.</p>
</div>
<div class="paragraph">
<p>As a baseline within <code class="notranslate">BasicTypeRegistry</code>, Hibernate follows the recommended mappings of JDBC for Java types. JDBC recommends mapping Strings to VARCHAR, which is the exact mapping that <code class="notranslate">StringType</code> handles. So that is the baseline mapping within <code class="notranslate">BasicTypeRegistry</code> for Strings.</p>
</div>
<div class="paragraph">
<p>Applications can also extend (add new <code class="notranslate">BasicType</code> registrations) or override (replace an existing <code class="notranslate">BasicType</code> registration) using one of the <code class="notranslate">MetadataBuilder#applyBasicType</code> methods or the <code class="notranslate">MetadataBuilder#applyTypes</code> method during bootstrap. For more details, see <a href="#basic-custom-type">Custom BasicTypes</a> section.</p>
</div>
</div>
<div class="sect3">
<h4 id="basic-type-annotation"><a class="anchor" href="#basic-type-annotation"></a>2.3.5. Explicit BasicTypes</h4>
<div class="paragraph">
<p>Sometimes you want a particular attribute to be handled differently. Occasionally Hibernate will implicitly pick a <code class="notranslate">BasicType</code> that you do not want (and for some reason you do not want to adjust the <code class="notranslate">BasicTypeRegistry</code>).</p>
</div>
<div class="paragraph">
<p>In these cases, you must explicitly tell Hibernate the <code class="notranslate">BasicType</code> to use, via the <code class="notranslate">org.hibernate.annotations.Type</code> annotation.</p>
</div>
<div id="basic-type-annotation-example" class="exampleblock">
<div class="title">
Example 6. Using
<code class="notranslate">@org.hibernate.annotations.Type</code>
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">@Entity(name = "Product")
public class Product {

	@Id
	private Integer id;

	private String sku;

	@org.hibernate.annotations.Type( type = "nstring" )
	private String name;

	@org.hibernate.annotations.Type( type = "materialized_nclob" )
	private String description;
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>This tells Hibernate to store the Strings as nationalized data. This is just for illustration purposes; for better ways to indicate nationalized character data see <a href="#basic-nationalized">Mapping Nationalized Character Data</a> section.</p>
</div>
<div class="paragraph">
<p>Additionally, the description is to be handled as a LOB. Again, for better ways to indicate LOBs see <a href="#basic-lob">Mapping LOBs</a> section.</p>
</div>
<div class="paragraph">
<p>The <code class="notranslate">org.hibernate.annotations.Type#type</code> attribute can name any of the following:</p>
</div>
<div class="ulist">
<ul>
<li> <p>Fully qualified name of any <code class="notranslate">org.hibernate.type.Type</code> implementation</p> </li>
<li> <p>Any key registered with <code class="notranslate">BasicTypeRegistry</code></p> </li>
<li> <p>The name of any known <em>type definitions</em></p> </li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="basic-custom-type"><a class="anchor" href="#basic-custom-type"></a>2.3.6. Custom BasicTypes</h4>
<div class="paragraph">
<p>Hibernate makes it relatively easy for developers to create their own basic type mappings type. For example, you might want to persist properties of type <code class="notranslate">java.util.BigInteger</code> to <code class="notranslate">VARCHAR</code> columns, or support completely new types.</p>
</div>
<div class="paragraph">
<p>There are two approaches to developing a custom type:</p>
</div>
<div class="ulist">
<ul>
<li> <p>implementing a <code class="notranslate">BasicType</code> and registering it</p> </li>
<li> <p>implementing a <code class="notranslate">UserType</code> which doesn’t require type registration </p> </li>
</ul>
</div>
<div class="paragraph">
<p>As a means of illustrating the different approaches, let’s consider a use case where we need to support a <code class="notranslate">java.util.BitSet</code> mapping that’s stored as a VARCHAR.</p>
</div>
<div class="sect4">
<h5 id="basic-custom-type-BasicType"><a class="anchor" href="#basic-custom-type-BasicType"></a>Implementing a <code class="notranslate">BasicType</code> </h5>
<div class="paragraph">
<p>The first approach is to directly implement the <code class="notranslate">BasicType</code> interface. </p>
</div>
<div class="admonitionblock note">
<table>
<tbody>
<tr>
<td class="icon"> <i class="fa icon-note" title="Note"></i> </td>
<td class="content">
<div class="paragraph">
<p>Because the <code class="notranslate">BasicType</code> interface has a lot of methods to implement, if the value is stored in a single database column, it’s much more convenient to extend the <code class="notranslate">AbstractStandardBasicType</code> or the <code class="notranslate">AbstractSingleColumnStandardBasicType</code> Hibernate classes.</p>
</div> </td>
</tr>
</tbody>
</table>
</div>
<div class="paragraph">
<p>First, we need to extend the <code class="notranslate">AbstractSingleColumnStandardBasicType</code> like this:</p>
</div>
<div id="basic-custom-type-BitSetType-example" class="exampleblock">
<div class="title">
Example 7. Custom
<code class="notranslate">BasicType</code> implementation
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">public class BitSetType
        extends AbstractSingleColumnStandardBasicType&lt;BitSet&gt;
        implements DiscriminatorType&lt;BitSet&gt; {

    public static final BitSetType INSTANCE = new BitSetType();

    public BitSetType() {
        super( VarcharTypeDescriptor.INSTANCE, BitSetTypeDescriptor.INSTANCE );
    }

    @Override
    public BitSet stringToObject(String xml) throws Exception {
        return fromString( xml );
    }

    @Override
    public String objectToSQLString(BitSet value, Dialect dialect) throws Exception {
        return toString( value );
    }

    @Override
    public String getName() {
        return "bitset";
    }

}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>The <code class="notranslate">AbstractSingleColumnStandardBasicType</code> requires an <code class="notranslate">sqlTypeDescriptor</code> and a <code class="notranslate">javaTypeDescriptor</code>. The <code class="notranslate">sqlTypeDescriptor</code> is <code class="notranslate">VarcharTypeDescriptor.INSTANCE</code> because the database column is a VARCHAR. On the Java side, we need to use a <code class="notranslate">BitSetTypeDescriptor</code> instance which can be implemented like this: </p>
</div>
<div id="basic-custom-type-BitSetTypeDescriptor-example" class="exampleblock">
<div class="title">
Example 8. Custom
<code class="notranslate">AbstractTypeDescriptor</code> implementation
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">public class BitSetTypeDescriptor extends AbstractTypeDescriptor&lt;BitSet&gt; {

    private static final String DELIMITER = ",";

    public static final BitSetTypeDescriptor INSTANCE = new BitSetTypeDescriptor();

    public BitSetTypeDescriptor() {
        super( BitSet.class );
    }

    @Override
    public String toString(BitSet value) {
        StringBuilder builder = new StringBuilder();
        for ( long token : value.toLongArray() ) {
            if ( builder.length() &gt; 0 ) {
                builder.append( DELIMITER );
            }
            builder.append( Long.toString( token, 2 ) );
        }
        return builder.toString();
    }

    @Override
    public BitSet fromString(String string) {
        if ( string == null || string.isEmpty() ) {
            return null;
        }
        String[] tokens = string.split( DELIMITER );
        long[] values = new long[tokens.length];

        for ( int i = 0; i &lt; tokens.length; i++ ) {
            values[i] = Long.valueOf( tokens[i], 2 );
        }
        return BitSet.valueOf( values );
    }

    @SuppressWarnings({"unchecked"})
    public &lt;X&gt; X unwrap(BitSet value, Class&lt;X&gt; type, WrapperOptions options) {
        if ( value == null ) {
            return null;
        }
        if ( BitSet.class.isAssignableFrom( type ) ) {
            return (X) value;
        }
        if ( String.class.isAssignableFrom( type ) ) {
            return (X) toString( value);
        }
        throw unknownUnwrap( type );
    }

    public &lt;X&gt; BitSet wrap(X value, WrapperOptions options) {
        if ( value == null ) {
            return null;
        }
        if ( String.class.isInstance( value ) ) {
            return fromString( (String) value );
        }
        if ( BitSet.class.isInstance( value ) ) {
            return (BitSet) value;
        }
        throw unknownWrap( value.getClass() );
    }
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>The <code class="notranslate">unwrap</code> method is used when passing a <code class="notranslate">BitSet</code> as a <code class="notranslate">PreparedStatement</code> bind parameter, while the <code class="notranslate">wrap</code> method is used to transform the JDBC column value object (e.g. <code class="notranslate">String</code> in our case) to the actual mapping object type (e.g. <code class="notranslate">BitSet</code> in this example).</p>
</div>
<div class="paragraph">
<p>The <code class="notranslate">BasicType</code> must be registered, and this can be done at bootstrapping time:</p>
</div>
<div id="basic-custom-type-register-BasicType-example" class="exampleblock">
<div class="title">
Example 9. Register a Custom
<code class="notranslate">BasicType</code> implementation
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">configuration.registerTypeContributor( (typeContributions, serviceRegistry) -&gt; {
	typeContributions.contributeType( BitSetType.INSTANCE );
} );</code></pre>
</div>
</div>
<div class="paragraph">
<p>or using the <code class="notranslate">MetadataBuilder</code></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">ServiceRegistry standardRegistry =
    new StandardServiceRegistryBuilder().build();

MetadataSources sources = new MetadataSources( standardRegistry );

MetadataBuilder metadataBuilder = sources.getMetadataBuilder();

metadataBuilder.applyBasicType( BitSetType.INSTANCE );</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>With the new <code class="notranslate">BitSetType</code> being registered as <code class="notranslate">bitset</code>, the entity mapping looks like this:</p>
</div>
<div id="basic-custom-type-BitSetType-mapping-example" class="exampleblock">
<div class="title">
Example 10. Custom
<code class="notranslate">BasicType</code> mapping
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">@Entity(name = "Product")
public static class Product {

	@Id
	private Integer id;

	@Type( type = "bitset" )
	private BitSet bitSet;

	public Integer getId() {
		return id;
	}

	//Getters and setters are omitted for brevity
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>Alternatively, you can use the <code class="notranslate">@TypeDef</code> and skip the registration phase:</p>
</div>
<div id="basic-custom-type-BitSetTypeDef-mapping-example" class="exampleblock">
<div class="title">
Example 11. Using
<code class="notranslate">@TypeDef</code> to register a custom Type
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">@Entity(name = "Product")
@TypeDef(
	name = "bitset",
	defaultForType = BitSet.class,
	typeClass = BitSetType.class
)
public static class Product {

	@Id
	private Integer id;

	private BitSet bitSet;

	//Getters and setters are omitted for brevity
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>To validate this new <code class="notranslate">BasicType</code> implementation, we can test it as follows:</p>
</div>
<div id="basic-custom-type-BitSetType-persistence-example" class="exampleblock">
<div class="title">
Example 12. Persisting the custom
<code class="notranslate">BasicType</code>
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">BitSet bitSet = BitSet.valueOf( new long[] {1, 2, 3} );

doInHibernate( this::sessionFactory, session -&gt; {
	Product product = new Product( );
	product.setId( 1 );
	product.setBitSet( bitSet );
	session.persist( product );
} );

doInHibernate( this::sessionFactory, session -&gt; {
	Product product = session.get( Product.class, 1 );
	assertEquals(bitSet, product.getBitSet());
} );</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>When executing this unit test, Hibernate generates the following SQL statements: </p>
</div>
<div id="basic-custom-type-BitSetType-persistence-sql-example" class="exampleblock">
<div class="title">
Example 13. Persisting the custom
<code class="notranslate">BasicType</code>
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">DEBUG SQL:92 -
    insert
    into
        Product
        (bitSet, id)
    values
        (?, ?)

TRACE BasicBinder:65 - binding parameter [1] as [VARCHAR] - [{0, 65, 128, 129}]
TRACE BasicBinder:65 - binding parameter [2] as [INTEGER] - [1]

DEBUG SQL:92 -
    select
        bitsettype0_.id as id1_0_0_,
        bitsettype0_.bitSet as bitSet2_0_0_
    from
        Product bitsettype0_
    where
        bitsettype0_.id=?

TRACE BasicBinder:65 - binding parameter [1] as [INTEGER] - [1]
TRACE BasicExtractor:61 - extracted value ([bitSet2_0_0_] : [VARCHAR]) - [{0, 65, 128, 129}]</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>As you can see, the <code class="notranslate">BitSetType</code> takes care of the <em>Java-to-SQL</em> and <em>SQL-to-Java</em> type conversion.</p>
</div>
</div>
<div class="sect4">
<h5 id="basic-custom-type-UserType"><a class="anchor" href="#basic-custom-type-UserType"></a>Implementing a <code class="notranslate">UserType</code></h5>
<div class="paragraph">
<p>The second approach is to implement the <code class="notranslate">UserType</code> interface.</p>
</div>
<div id="basic-custom-type-BitSetUserType-example" class="exampleblock">
<div class="title">
Example 14. Custom
<code class="notranslate">UserType</code> implementation
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">public class BitSetUserType implements UserType {

	public static final BitSetUserType INSTANCE = new BitSetUserType();

    private static final Logger log = Logger.getLogger( BitSetUserType.class );

    @Override
    public int[] sqlTypes() {
        return new int[] {StringType.INSTANCE.sqlType()};
    }

    @Override
    public Class returnedClass() {
        return BitSet.class;
    }

    @Override
    public boolean equals(Object x, Object y)
			throws HibernateException {
        return Objects.equals( x, y );
    }

    @Override
    public int hashCode(Object x)
			throws HibernateException {
        return Objects.hashCode( x );
    }

    @Override
    public Object nullSafeGet(
            ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner)
            throws HibernateException, SQLException {
        String columnName = names[0];
        String columnValue = (String) rs.getObject( columnName );
        log.debugv("Result set column {0} value is {1}", columnName, columnValue);
        return columnValue == null ? null :
				BitSetTypeDescriptor.INSTANCE.fromString( columnValue );
    }

    @Override
    public void nullSafeSet(
            PreparedStatement st, Object value, int index, SharedSessionContractImplementor session)
            throws HibernateException, SQLException {
        if ( value == null ) {
            log.debugv("Binding null to parameter {0} ",index);
            st.setNull( index, Types.VARCHAR );
        }
        else {
            String stringValue = BitSetTypeDescriptor.INSTANCE.toString( (BitSet) value );
            log.debugv("Binding {0} to parameter {1} ", stringValue, index);
            st.setString( index, stringValue );
        }
    }

    @Override
    public Object deepCopy(Object value)
			throws HibernateException {
        return value == null ? null :
            BitSet.valueOf( BitSet.class.cast( value ).toLongArray() );
    }

    @Override
    public boolean isMutable() {
        return true;
    }

    @Override
    public Serializable disassemble(Object value)
			throws HibernateException {
        return (BitSet) deepCopy( value );
    }

    @Override
    public Object assemble(Serializable cached, Object owner)
			throws HibernateException {
        return deepCopy( cached );
    }

    @Override
    public Object replace(Object original, Object target, Object owner)
			throws HibernateException {
        return deepCopy( original );
    }
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>The entity mapping looks as follows:</p>
</div>
<div id="basic-custom-type-BitSetUserType-mapping-example" class="exampleblock">
<div class="title">
Example 15. Custom
<code class="notranslate">UserType</code> mapping
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">@Entity(name = "Product")
public static class Product {

	@Id
	private Integer id;

	@Type( type = "bitset" )
	private BitSet bitSet;

	//Constructors, getters, and setters are omitted for brevity
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>In this example, the <code class="notranslate">UserType</code> is registered under the <code class="notranslate">bitset</code> name, and this is done like this:</p>
</div>
<div id="basic-custom-type-register-UserType-example" class="exampleblock">
<div class="title">
Example 16. Register a Custom
<code class="notranslate">UserType</code> implementation
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">configuration.registerTypeContributor( (typeContributions, serviceRegistry) -&gt; {
	typeContributions.contributeType( BitSetUserType.INSTANCE, "bitset");
} );</code></pre>
</div>
</div>
<div class="paragraph">
<p>or using the <code class="notranslate">MetadataBuilder</code></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">ServiceRegistry standardRegistry =
    new StandardServiceRegistryBuilder().build();

MetadataSources sources = new MetadataSources( standardRegistry );

MetadataBuilder metadataBuilder = sources.getMetadataBuilder();

metadataBuilder.applyBasicType( BitSetUserType.INSTANCE, "bitset" );</code></pre>
</div>
</div>
</div>
</div>
<div class="admonitionblock note">
<table>
<tbody>
<tr>
<td class="icon"> <i class="fa icon-note" title="Note"></i> </td>
<td class="content">
<div class="paragraph">
<p>Like <code class="notranslate">BasicType</code>, you can also register the <code class="notranslate">UserType</code> using a simple name.</p>
</div>
<div class="paragraph">
<p>Without registering a name, the <code class="notranslate">UserType</code> mapping requires the fully qualified class name:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">@Type( type = "org.hibernate.userguide.mapping.basic.BitSetUserType" )</code></pre>
</div>
</div> </td>
</tr>
</tbody>
</table>
</div>
<div class="paragraph">
<p>When running the previous test case against the <code class="notranslate">BitSetUserType</code> entity mapping, Hibernate executed the following SQL statements:</p>
</div>
<div id="basic-custom-type-BitSetUserType-persistence-sql-example" class="exampleblock">
<div class="title">
Example 17. Persisting the custom
<code class="notranslate">BasicType</code>
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">DEBUG SQL:92 -
    insert
    into
        Product
        (bitSet, id)
    values
        (?, ?)

DEBUG BitSetUserType:71 - Binding 1,10,11 to parameter 1
TRACE BasicBinder:65 - binding parameter [2] as [INTEGER] - [1]

DEBUG SQL:92 -
    select
        bitsetuser0_.id as id1_0_0_,
        bitsetuser0_.bitSet as bitSet2_0_0_
    from
        Product bitsetuser0_
    where
        bitsetuser0_.id=?

TRACE BasicBinder:65 - binding parameter [1] as [INTEGER] - [1]
DEBUG BitSetUserType:56 - Result set column bitSet2_0_0_ value is 1,10,11</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="basic-enums"><a class="anchor" href="#basic-enums"></a>2.3.7. Mapping enums</h4>
<div class="paragraph">
<p>Hibernate supports the mapping of Java enums as basic value types in a number of different ways.</p>
</div>
<div class="sect4">
<h5 id="basic-enums-Enumerated"><a class="anchor" href="#basic-enums-Enumerated"></a><code class="notranslate">@Enumerated</code></h5>
<div class="paragraph">
<p>The original JPA-compliant way to map enums was via the <code class="notranslate">@Enumerated</code> or <code class="notranslate">@MapKeyEnumerated</code> for map keys annotations, working on the principle that the enum values are stored according to one of 2 strategies indicated by <code class="notranslate">javax.persistence.EnumType</code>:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">
<code class="notranslate">ORDINAL</code>
</dt>
<dd>
<p>stored according to the enum value’s ordinal position within the enum class, as indicated by <code class="notranslate">java.lang.Enum#ordinal</code></p>
</dd>
<dt class="hdlist1">
<code class="notranslate">STRING</code>
</dt>
<dd>
<p>stored according to the enum value’s name, as indicated by <code class="notranslate">java.lang.Enum#name</code></p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Assuming the following enumeration:</p>
</div>
<div class="exampleblock">
<div class="title">
Example 18.
<code class="notranslate">PhoneType</code> enumeration
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">public enum PhoneType {
    LAND_LINE,
    MOBILE;
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>In the ORDINAL example, the <code class="notranslate">phone_type</code> column is defined as a (nullable) INTEGER type and would hold:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">
<code class="notranslate">NULL</code>
</dt>
<dd>
<p>For null values</p>
</dd>
<dt class="hdlist1">
<code class="notranslate">0</code>
</dt>
<dd>
<p>For the <code class="notranslate">LAND_LINE</code> enum</p>
</dd>
<dt class="hdlist1">
<code class="notranslate">1</code>
</dt>
<dd>
<p>For the <code class="notranslate">MOBILE</code> enum</p>
</dd>
</dl>
</div>
<div id="basic-enums-Enumerated-ordinal-example" class="exampleblock">
<div class="title">
Example 19.
<code class="notranslate">@Enumerated(ORDINAL)</code> example
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">@Entity(name = "Phone")
public static class Phone {

	@Id
	private Long id;

	@Column(name = "phone_number")
	private String number;

	@Enumerated(EnumType.ORDINAL)
	@Column(name = "phone_type")
	private PhoneType type;

	//Getters and setters are omitted for brevity

}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>When persisting this entity, Hibernate generates the following SQL statement:</p>
</div>
<div id="basic-enums-Enumerated-ordinal-persistence-example" class="exampleblock">
<div class="title">
Example 20. Persisting an entity with an
<code class="notranslate">@Enumerated(ORDINAL)</code> mapping
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">Phone phone = new Phone( );
phone.setId( 1L );
phone.setNumber( "123-456-78990" );
phone.setType( PhoneType.MOBILE );
entityManager.persist( phone );</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-SQL" data-lang="SQL">INSERT INTO Phone (phone_number, phone_type, id)
VALUES ('123-456-78990', 2, 1)</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>In the STRING example, the <code class="notranslate">phone_type</code> column is defined as a (nullable) VARCHAR type and would hold:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">
<code class="notranslate">NULL</code>
</dt>
<dd>
<p>For null values</p>
</dd>
<dt class="hdlist1">
<code class="notranslate">LAND_LINE</code>
</dt>
<dd>
<p>For the <code class="notranslate">LAND_LINE</code> enum</p>
</dd>
<dt class="hdlist1">
<code class="notranslate">MOBILE</code>
</dt>
<dd>
<p>For the <code class="notranslate">MOBILE</code> enum</p>
</dd>
</dl>
</div>
<div id="basic-enums-Enumerated-string-example" class="exampleblock">
<div class="title">
Example 21.
<code class="notranslate">@Enumerated(STRING)</code> example
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">@Entity(name = "Phone")
public static class Phone {

	@Id
	private Long id;

	@Column(name = "phone_number")
	private String number;

	@Enumerated(EnumType.STRING)
	@Column(name = "phone_type")
	private PhoneType type;

	//Getters and setters are omitted for brevity

}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>Persisting the same entity as in the <code class="notranslate">@Enumerated(ORDINAL)</code> example, Hibernate generates the following SQL statement:</p>
</div>
<div id="basic-enums-Enumerated-string-persistence-example" class="exampleblock">
<div class="title">
Example 22. Persisting an entity with an
<code class="notranslate">@Enumerated(STRING)</code> mapping
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-SQL" data-lang="SQL">INSERT INTO Phone (phone_number, phone_type, id)
VALUES ('123-456-78990', 'MOBILE', 1)</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect4">
<h5 id="basic-enums-attribute-converter"><a class="anchor" href="#basic-enums-attribute-converter"></a>AttributeConverter</h5>
<div class="paragraph">
<p>Let’s consider the following <code class="notranslate">Gender</code> enum which stores its values using the <code class="notranslate">'M'</code> and <code class="notranslate">'F'</code> codes.</p>
</div>
<div id="basic-enums-converter-example" class="exampleblock">
<div class="title">
Example 23. Enum with a custom constructor
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">public enum Gender {

    MALE( 'M' ),
    FEMALE( 'F' );

    private final char code;

    Gender(char code) {
        this.code = code;
    }

    public static Gender fromCode(char code) {
        if ( code == 'M' || code == 'm' ) {
            return MALE;
        }
        if ( code == 'F' || code == 'f' ) {
            return FEMALE;
        }
        throw new UnsupportedOperationException(
            "The code " + code + " is not supported!"
        );
    }

    public char getCode() {
        return code;
    }
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>You can map enums in a JPA compliant way using a JPA 2.1 AttributeConverter.</p>
</div>
<div id="basic-enums-attribute-converter-example" class="exampleblock">
<div class="title">
Example 24. Enum mapping with
 <code class="notranslate">AttributeConverter</code> example
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">@Entity(name = "Person")
public static class Person {

	@Id
	private Long id;

	private String name;

	@Convert( converter = GenderConverter.class )
	public Gender gender;

	//Getters and setters are omitted for brevity

}

@Converter
public static class GenderConverter
		implements AttributeConverter&lt;Gender, Character&gt; {

	public Character convertToDatabaseColumn( Gender value ) {
		if ( value == null ) {
			return null;
		}

		return value.getCode();
	}

	public Gender convertToEntityAttribute( Character value ) {
		if ( value == null ) {
			return null;
		}

		return Gender.fromCode( value );
	}
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>Here, the gender column is defined as a CHAR type and would hold:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">
<code class="notranslate">NULL</code>
</dt>
<dd>
<p>For null values</p>
</dd>
<dt class="hdlist1">
<code class="notranslate">'M'</code>
</dt>
<dd>
<p>For the <code class="notranslate">MALE</code> enum</p>
</dd>
<dt class="hdlist1">
<code class="notranslate">'F'</code>
</dt>
<dd>
<p>For the <code class="notranslate">FEMALE</code> enum</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>For additional details on using AttributeConverters, see <a href="#basic-jpa-convert">JPA 2.1 AttributeConverters</a> section.</p>
</div>
<div class="admonitionblock note">
<table>
<tbody>
<tr>
<td class="icon"> <i class="fa icon-note" title="Note"></i> </td>
<td class="content">
<div class="paragraph">
<p>JPA explicitly disallows the use of an <code class="notranslate">AttributeConverter</code> with an attribute marked as <code class="notranslate">@Enumerated</code>.</p>
</div>
<div class="paragraph">
<p>So, when using the <code class="notranslate">AttributeConverter</code> approach, be sure not to mark the attribute as <code class="notranslate">@Enumerated</code>.</p>
</div> </td>
</tr>
</tbody>
</table>
</div>
<div class="sect5">
<h6 id="basic-attribute-converter-query-parameter"><a class="anchor" href="#basic-attribute-converter-query-parameter"></a>Using the AttributeConverter entity property as a query parameter</h6>
<div class="paragraph">
<p>Assuming you have the following entity:</p>
</div>
<div id="basic-attribute-converter-query-parameter-entity-example" class="exampleblock">
<div class="title">
Example 25.
<code class="notranslate">Photo</code> entity with
<code class="notranslate">AttributeConverter</code>
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">@Entity(name = "Photo")
public static class Photo {

	@Id
	private Integer id;

	private String name;

	@Convert(converter = CaptionConverter.class)
	private Caption caption;

	//Getters and setters are omitted for brevity
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>And the <code class="notranslate">Caption</code> class looks as follows:</p>
</div>
<div id="basic-attribute-converter-query-parameter-object-example" class="exampleblock">
<div class="title">
Example 26.
<code class="notranslate">Caption</code> Java object
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">public static class Caption {

	private String text;

	public Caption(String text) {
		this.text = text;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	@Override
	public boolean equals(Object o) {
		if ( this == o ) {
			return true;
		}
		if ( o == null || getClass() != o.getClass() ) {
			return false;
		}
		Caption caption = (Caption) o;
		return text != null ? text.equals( caption.text ) : caption.text == null;

	}

	@Override
	public int hashCode() {
		return text != null ? text.hashCode() : 0;
	}
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>And we have an <code class="notranslate">AttributeConverter</code> to handle the <code class="notranslate">Caption</code> Java object:</p>
</div>
<div id="basic-attribute-converter-query-parameter-converter-example" class="exampleblock">
<div class="title">
Example 27.
<code class="notranslate">Caption</code> Java object AttributeConverter
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">public static class CaptionConverter
		implements AttributeConverter&lt;Caption, String&gt; {

	@Override
	public String convertToDatabaseColumn(Caption attribute) {
		return attribute.getText();
	}

	@Override
	public Caption convertToEntityAttribute(String dbData) {
		return new Caption( dbData );
	}
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>Traditionally, you could only use the DB data <code class="notranslate">Caption</code> representation, which in our case is a <code class="notranslate">String</code>, when referencing the <code class="notranslate">caption</code> entity property.</p>
</div>
<div id="basic-attribute-converter-query-parameter-converter-dbdata-example" class="exampleblock">
<div class="title">
Example 28. Filtering by the
<code class="notranslate">Caption</code> property using the DB data representation
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">Photo photo = entityManager.createQuery(
	"select p " +
	"from Photo p " +
	"where upper(caption) = upper(:caption) ", Photo.class )
.setParameter( "caption", "Nicolae Grigorescu" )
.getSingleResult();</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>In order to use the Java object <code class="notranslate">Caption</code> representation, you have to get the associated Hibernate <code class="notranslate">Type</code>.</p>
</div>
<div id="basic-attribute-converter-query-parameter-converter-object-example" class="exampleblock">
<div class="title">
Example 29. Filtering by the
<code class="notranslate">Caption</code> property using the Java Object representation
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">SessionFactory sessionFactory = entityManager.getEntityManagerFactory()
		.unwrap( SessionFactory.class );

MetamodelImplementor metamodelImplementor = (MetamodelImplementor) sessionFactory.getMetamodel();

Type captionType = metamodelImplementor
		.entityPersister( Photo.class.getName() )
		.getPropertyType( "caption" );

Photo photo = (Photo) entityManager.createQuery(
	"select p " +
	"from Photo p " +
	"where upper(caption) = upper(:caption) ", Photo.class )
.unwrap( Query.class )
.setParameter( "caption", new Caption("Nicolae Grigorescu"), captionType)
.getSingleResult();</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>By passing the associated Hibernate <code class="notranslate">Type</code>, you can use the <code class="notranslate">Caption</code> object when binding the query parameter value.</p>
</div>
</div>
<div class="sect5">
<h6 id="basic-hbm-attribute-converter"><a class="anchor" href="#basic-hbm-attribute-converter"></a>Mapping an AttributeConverter using HBM mappings</h6>
<div class="paragraph">
<p>When using HBM mappings, you can still make use of the JPA <code class="notranslate">AttributeConverter</code> because Hibernate supports such mapping via the <code class="notranslate">type</code> attribute as demonstrated by the following example. </p>
</div>
<div class="paragraph">
<p>Let’s consider we have an application-specific <code class="notranslate">Money</code> type:</p>
</div>
<div id="basic-hbm-attribute-converter-mapping-money-example" class="exampleblock">
<div class="title">
Example 30. Application-specific
<code class="notranslate">Money</code> type
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">public class Money {

    private long cents;

    public Money(long cents) {
        this.cents = cents;
    }

    public long getCents() {
        return cents;
    }

    public void setCents(long cents) {
        this.cents = cents;
    }
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>Now, we want to use the <code class="notranslate">Money</code> type when mapping the <code class="notranslate">Account</code> entity:</p>
</div>
<div id="basic-hbm-attribute-converter-mapping-account-example" class="exampleblock">
<div class="title">
Example 31.
<code class="notranslate">Account</code> entity using the
<code class="notranslate">Money</code> type
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">public class Account {

    private Long id;

    private String owner;

    private Money balance;

    //Getters and setters are omitted for brevity
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>Since Hibernate has no knowledge how to persist the <code class="notranslate">Money</code> type, we could use a JPA <code class="notranslate">AttributeConverter</code> to transform the <code class="notranslate">Money</code> type as a <code class="notranslate">Long</code>. For this purpose, we are going to use the following <code class="notranslate">MoneyConverter</code> utility:</p>
</div>
<div id="basic-hbm-attribute-converter-mapping-moneyconverter-example" class="exampleblock">
<div class="title">
Example 32.
<code class="notranslate">MoneyConverter</code> implementing the JPA
<code class="notranslate">AttributeConverter</code> interface
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">public class MoneyConverter
        implements AttributeConverter&lt;Money, Long&gt; {

    @Override
    public Long convertToDatabaseColumn(Money attribute) {
        return attribute == null ? null : attribute.getCents();
    }

    @Override
    public Money convertToEntityAttribute(Long dbData) {
        return dbData == null ? null : new Money( dbData );
    }
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>To map the <code class="notranslate">MoneyConverter</code> using HBM configuration files you need to use the <code class="notranslate">converted::</code> prefix in the <code class="notranslate">type</code> attribute of the <code class="notranslate">property</code> element.</p>
</div>
<div id="basic-hbm-attribute-converter-mapping-xml-config-example" class="exampleblock">
<div class="title">
Example 33. HBM mapping for
<code class="notranslate">AttributeConverter</code>
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&gt;

&lt;hibernate-mapping package="org.hibernate.userguide.mapping.converter.hbm"&gt;
    &lt;class name="Account" table="account" &gt;
        &lt;id name="id"/&gt;

        &lt;property name="owner"/&gt;

        &lt;property name="balance"
            type="converted::org.hibernate.userguide.mapping.converter.hbm.MoneyConverter"/&gt;

    &lt;/class&gt;
&lt;/hibernate-mapping&gt;</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect4">
<h5 id="basic-enums-custom-type"><a class="anchor" href="#basic-enums-custom-type"></a>Custom type</h5>
<div class="paragraph">
<p>You can also map enums using a Hibernate custom type mapping. Let’s again revisit the Gender enum example, this time using a custom Type to store the more standardized <code class="notranslate">'M'</code> and <code class="notranslate">'F'</code> codes.</p>
</div>
<div id="basic-enums-custom-type-example" class="exampleblock">
<div class="title">
Example 34. Enum mapping with custom Type example
</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight notranslate"><code class="language-JAVA" data-lang="JAVA">@Entity(name = "Person")
public static class Person {

	@Id
	private Long id;

	private String name;

	@Type( type = "org.hibernate.userguide.mapping.basic.GenderType" )
	public Gender gender;

	//Getters and setters are omitted for brevity

}

public class GenderType extends AbstractSingleColumnStandardBasicType&lt;Gender&gt; {

    public static final GenderType INSTANCE = new GenderType();

    public GenderType() {
        super(
            CharTypeDescriptor.INSTANCE,
            GenderJavaTypeDescriptor.INSTANCE
        );
    }

    public String getName() {
        return "gender";
    }

    @Override
    protected boolean registerUnderJavaType() {
        return true;
    }
}

public class GenderJavaTypeDescriptor extends AbstractTypeDescriptor&lt;Gender&gt; {

    public static final GenderJavaTypeDescriptor INSTANCE =
        new GenderJavaTypeDescriptor();

    protected GenderJavaTypeDescriptor() {
        super( Gender.class );
    }

    public String toString(Gender value) {
        return value == null ? null : value.name();
    }

    public Gender fromString(String string) {
        return string == null ? null : Gender.valueOf( string );
    }

    public &lt;X&gt; X unwrap(Gender value, Class&lt;X&gt; type, WrapperOptions options) {
        return CharacterTypeDescriptor.INSTANCE.unwrap(
            value == null ? null : value.getCode(),
            type,
            options
        );
    }

    public &lt;X&gt; Gender wrap(X value, WrapperOptions options) {
        return Gender.fromCode(
            CharacterTypeDescriptor.INSTANCE.wrap( value, options )
        );
    }
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>Again, the gender column is defined as a CHAR type and would hold:</p>
</div>
 <div class="dlist">
<dl>
<dt class="hdlist1">
<code class="notranslate">NULL</code>
</dt>
<dd>
<p>For null values</p>
</dd>
<dt class="hdlist1">
<code class="notranslate">'M'</code>
</dt>
<dd>
<p>For the <code class="notranslate">MALE</code> enum</p>
</dd>
<dt class="hdlist1">
<code class="notranslate">'F'</code>
</dt>
<dd>
<p>For the <code class="notranslate">FEMALE</code> enum</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>For additional details on using custom types, see <a href="#basic-custom-type">Custom BasicTypes</a> section.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="basic-lob"><a class="anchor" href="#basic-lob"></a>2.3.8. Mapping LOBs</h4>
<div class="paragraph">
<p>Mapping LOBs (database Large Objects) come in 2 forms, those using the JDBC locator types and those materializing the LOB data.</p>
</div>
<div class="paragraph">
<p>JDBC LOB locators exist to allow efficient access to the LOB data. They allow the JDBC driver to stream parts of the LOB data as needed, potentially freeing up memory space. However, they can be unnatural to deal with and have certain limitations. For example, a LOB locator is only portably valid during the duration of the transaction in which it was obtained.</p>
</div>
<div class="paragraph">
<p>The idea of materialized LOBs is to trade-off the potential efficiency (not all drivers handle LOB data efficiently) for a more natural programming paradigm using familiar Java types such as <code class="notranslate">String&lt;</code></p>
</div>
</div>
</div>
</div>
</div></div>
</div>
</section>
<div class="right-sidebar">
<div class="affix"><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6108808167664152" data-ad-slot="3102929424" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></div>
</div>
</div>
<div class="ft">
<a href="#toolbar-title" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a>
<footer class="footer">
<div class="footer__container--normal">
<img alt="扫码关注公众号" title="扫码关注公众号" src="static/picture/qr-code.png" width="170" height="170">
<div class="footer__description--normal">
<p class="paragraph footer__author--normal">Docs4dev<sup class="super">&#xAE;</sup>
</p>
<p class="paragraph footer__quote&#45;&#45;normal">
如果你在使用过程中遇到任何问题，可以在 <a href="javascript:window.open('https://github.com/docs4dev/docs4dev-issues');" target="_blank" rel="noopener noreferrer">这里<i class="fa fa-external-link"></i></a> 提issue。
</p>
<div class="footer__main--normal">
<p class="paragraph footer__main__paragraph--normal copyright" style="color: #666 !important;">
<a href="javascript:window.open('https://beian.miit.gov.cn/');">
蜀ICP备14021783号-6
</a>
</p>
<p class="paragraph footer__main__paragraph--normal copyright" style="color: #666 !important;">
Copyright &#xA9; Docs4dev all
right reserved, powered by <a href="index2.html" target="_blank">Docs4dev</a></p>
</div>
</div>
</div>
<div class="box__issues">
</div>
</footer>
</div>
</div>
</div>
</div>
</div>
<script>
  var hasToc = true;
  /*  var downloadable = /!*false*!/ false;
    var editable = /!*false*!/ false;
    var code = /!*"hibernate-orm"*!/ false;
    var version = /!*"5.4"*!/ false;
    var type = /!*"reference"*!/ false;
    var lang = /!*"en"*!/ 'en';
    //edit link
    require(["gitbook", "jQuery"], function (gitbook, $) {
      gitbook.events.bind('start', function (e, config) {
        // Add edit toolbar to left
        var chapterId = /!*24795*!/ 0;
        if (downloadable) {
          gitbook.toolbar.createButton({
            icon: 'fa fa-download',
            text: '下载',
            onClick: function () {
              window.open('/download?code=' + code + '&version=' + version + '&type=' + type + '&lang=' + lang);
            }
          });
        }
        if (editable) {
          gitbook.toolbar.createButton({
            icon: 'fa fa-edit',
            text: '编辑此页',
            onClick: function () {
              window.open('/docs/edit?chapterId=' + chapterId + '&lang=' + lang);
            }
          });
        }
      });
    });*/
</script>
<script>
    var code = "hibernate-orm";
    var lang = "en";
  </script>

<script src="static/js/autocomplete-js.js"></script>
<script src="static/js/app.min.js"></script>
<script src="static/js/search.min.js"></script>
</body>
</html>
